/**
* 顺时针图片旋转的方法
*
* @param request
* @param response
* @return
* @author julong 2013-8-29 下午09:12:47
*/
public void pictureRotationClockwise(HttpServletRequest request,HttpServletResponse response,PhotoTemp2 pt2){
response.setContentType("text/html; charset=GBK");
//获取smid
String smid = request.getParameter("smid");
//System.out.println(smid);
//获取原图片对象
PhotoTemp2 photoTemp2 = this.photoTemp2Service.getZp(smid);
//获取图片对象
byte[] imgBtye = photoTemp2.getZp();
//获取输入字节流
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(imgBtye);
//将byte数组转换为image对象 访问图像缓冲区的图像对象
BufferedImage bufferedImage;
PrintWriter out = null ;
ExcuteResult result;
try {
//获得图片对象
bufferedImage = ImageIO.read(byteArrayInputStream);
//获得当前的图片的高度和宽度
int thisHeight = bufferedImage.getHeight();
int thisWidth = bufferedImage.getWidth();
BufferedImage dstImage = null;
//创建图片矩阵向量旋转对象类表示
//2D 仿射变换,它执行从 2D 坐标到其他 2D 坐标的线性映射,保留了线的“直线性”和“平行性”。可以使用一系列平移、缩放、翻转、旋转和剪切来构造仿射变换。
AffineTransform affineTransform = new AffineTransform();
//设置图像平移的距离
//thisHeight - 坐标在 X 轴方向上平移的距离
//0 - 坐标在 Y 轴方向上平移的距离
affineTransform.translate(thisHeight, 0);
//创建一个新的画布
//旋转后 thisHeight图像的宽度 thisWidth 图像的高度
dstImage = new BufferedImage(thisHeight, thisWidth, bufferedImage.getType());
//设置图片旋转的角度 是X轴正半轴 向Y轴正半轴 旋转的角度
affineTransform.rotate(java.lang.Math.toRadians(90));
//执行源图像的线性2D映射
AffineTransformOp affineTransformOp = new AffineTransformOp(affineTransform,null);
//转换图片对象为bufferedImage对象
affineTransformOp.filter(bufferedImage, dstImage);
// 创建字节输入流
ByteArrayOutputStream byteArrayOutputStream =new ByteArrayOutputStream();
ImageIO.write(dstImage, "JPEG", byteArrayOutputStream);
//获取新图片的数组
byte[] newImg = byteArrayOutputStream.toByteArray();
photoTemp2.setZp(newImg);
//执行更新操作
result = this.photoTemp2Service.updateDrvPhotoTempZP(photoTemp2);

out = response.getWriter();
//System.err.println(result.getReturnCode());
//判断数据库是否更新成功如果成功则执行刷新的方法
if(1==result.getReturnCode()){
out.println("<script style='javascript/text'>parent.rotationBack();</script>");
}

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch(Exception e){
e.printStackTrace();
}finally{
if(out!=null)out.close();
}
//return new ModelAndView("dagl/lsda_drv_imgList");

}
/**
* 图片逆时针旋转的方法
*
* @param request
* @param response
* @param pt2
* @author julong 2013-8-30 下午03:26:27
*/
public void pictureRotationAntiClockwise(HttpServletRequest request,HttpServletResponse response,PhotoTemp2 pt2){
response.setContentType("text/html; charset=GBK");
//System.out.println("--------------------------------------------------------------------------");
//获取smid
String smid = request.getParameter("smid");
//System.out.println(smid);
//获取原图片对象
PhotoTemp2 photoTemp2 = this.photoTemp2Service.getZp(smid);
//获取图片对象
byte[] imgBtye = photoTemp2.getZp();
//获取输入字节流
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(imgBtye);
//将byte数组转换为image对象 访问图像缓冲区的图像对象
BufferedImage bufferedImage;
PrintWriter out = null ;
ExcuteResult result;
try {
//获得图片对象
bufferedImage = ImageIO.read(byteArrayInputStream);
//获得当前的图片的高度和宽度
int thisHeight = bufferedImage.getHeight();
int thisWidth = bufferedImage.getWidth();
BufferedImage dstImage = null;
//创建图片矩阵向量旋转对象类表示
//2D 仿射变换,它执行从 2D 坐标到其他 2D 坐标的线性映射,保留了线的“直线性”和“平行性”。可以使用一系列平移、缩放、翻转、旋转和剪切来构造仿射变换。
AffineTransform affineTransform = new AffineTransform();
//设置图像平移的距离
//0 - 坐标在 X 轴方向上平移的距离
//thisWidth - 坐标在 Y 轴方向上平移的距离
affineTransform.translate(0, thisWidth);
//创建一个新的画布
//旋转后 thisHeight图像的宽度 thisWidth 图像的高度
dstImage = new BufferedImage(thisHeight, thisWidth, bufferedImage.getType());
//设置图片旋转的角度 是X轴正半轴 向Y轴正半轴 旋转的角度
affineTransform.rotate(java.lang.Math.toRadians(270));
//执行源图像的线性2D映射
AffineTransformOp affineTransformOp = new AffineTransformOp(affineTransform,null);
//转换图片对象为bufferedImage对象
affineTransformOp.filter(bufferedImage, dstImage);
// 创建字节输入流
ByteArrayOutputStream byteArrayOutputStream =new ByteArrayOutputStream();
ImageIO.write(dstImage, "JPEG", byteArrayOutputStream);
//获取新图片的数组
byte[] newImg = byteArrayOutputStream.toByteArray();
photoTemp2.setZp(newImg);
//执行更新操作
result = this.photoTemp2Service.updateDrvPhotoTempZP(photoTemp2);

out = response.getWriter();
//System.err.println(result.getReturnCode());
//判断数据库是否更新成功如果成功则执行刷新的方法
if(1==result.getReturnCode()){
out.println("<script style='javascript/text'>parent.rotationBack();</script>");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch(Exception e){
e.printStackTrace();
}finally{
if(out!=null)out.close();
}
}


这种方式是图片从数据库中读出来  在旋转  后存入数据库中  测试成功  希望对您有所帮助