使用java怎么对图片的角度进行旋转

  介绍

这篇文章给大家介绍使用java怎么对图片的角度进行旋转,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

java可以用来干什么

java主要应用于:1。网页开发;2。Android开发;3。客户端开发;4。网页开发;5。企业级应用开发;6。Java大数据开发;7。游戏开发等。

<强>方法一:普通方法实现图片旋转

/* *   ,,*,图像旋转   ,,*,@param  src   ,,*,@param 天使   ,,* @return   */public 才能;static  BufferedImage 旋转(Image  src, double 天使),{   ,,,int  src_width =, src.getWidth(空);   ,,,int  src_height =, src.getHeight(空);   ,,,//,calculate 从而new  image 大小   ,,,Rectangle  rect_des =, CalcRotatedSize (new 矩形(new 维度(   ,,,,,,,,,src_width src_height),天使);   ,   ,,,BufferedImage  res =,空;   ,,,res =, new  BufferedImage (rect_des.width, rect_des.height,   ,,,,,,,BufferedImage.TYPE_3BYTE_BGR);   ,,,Graphics2D  g2 =, res.createGraphics ();   ,,,//变换   ,,,g2.translate ((rect_des.width 作用;src_width),/, 2,   ,,,,,,,(rect_des.height 作用;src_height),/, 2);   ,,,g2.rotate (Math.toRadians(天使),src_width /, 2, src_height /, 2);   ,   ,,,g2.drawImage (src, null,, null);   ,,,return  res;   ,,}   ,   public 才能static  Rectangle  CalcRotatedSize (Rectangle  src, double 天使),{   ,,,//,if  angel  is  greater  than  90年,学位,,need 用我方表示歉意do  some 转换   ,,,if  (angel 祝辞=,90),{   ,,,,,如果(angel /, 90, %, 2,==, 1) {   ,,,,,,,int  temp =, src.height;   ,,,,,,,src.height =, src.width;   ,,,,,,,src.width =,温度;   ,,,,,}   ,,,,,angel =, angel  %, 90;   ,,,}   ,   ,,,double  r =, Math.sqrt (src.height  *, src.height  +, src.width  *, src.width),/, 2;   ,,,double  len =, 2, *, sin (Math.toRadians(天使),/,2),*,r;   ,,,double  angel_alpha =, (Math.PI 安康;Math.toRadians(天使),/,2;   ,,,double  angel_dalta_width =, Math.atan((双),src.height /, src.width);   ,,,double  angel_dalta_height =, Math.atan((双),src.width /, src.height);   ,   ,,,int  len_dalta_width =, (int), (len  *, Math.cos (Math.PI 作用;angel_alpha   ,,,,,,,今天早上,angel_dalta_width));   ,,,len_dalta_width=len_dalta_width> 0 ? len_dalta_width: -len_dalta_width;   ,   ,,,int  len_dalta_height =, (int), (len  *, Math.cos (Math.PI 作用;angel_alpha   ,,,,,,,今天早上,angel_dalta_height));   ,,,len_dalta_height=len_dalta_height> 0 ? len_dalta_height: -len_dalta_height;   ,   ,,,int  des_width =, src.width  +, len_dalta_width  *, 2;   ,,,int  des_height =, src.height  +, len_dalta_height  *, 2;   ,,,des_width=des_width> 0 ? des_width: -des_width;   ,,,des_height=des_height> 0 ? des_height: -des_height;   ,,,return  new  java.awt.Rectangle (new 维度(des_width, des_height));   }

<>强方法二:opencv实现图片旋转

,/* *   ,,*,opencv实现图片旋转   ,,*,@param  splitImage   ,,*,@param 角   ,,* @return   */public 才能static  Mat  rotate3 (Mat  splitImage, double 角)   {才能   ,,,double  thera =, angle  *, Math.PI /, 180;   ,,,double  a =, sin(席拉);   ,,,double  b =, Math.cos(席拉);   ,   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

使用java怎么对图片的角度进行旋转