最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java實(shí)現(xiàn)圖片角度旋轉(zhuǎn)并獲得圖片信息

 更新時(shí)間:2019年02月10日 09:47:23   作者:fackyou200  
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)圖片角度旋轉(zhuǎn)并獲得圖片信息,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了java實(shí)現(xiàn)圖片角度旋轉(zhuǎn)并獲得圖片信息的具體代碼,供大家參考,具體內(nèi)容如下

public class Demo {
 
 /**
 * 調(diào)整圖片角度
 * make by dongxh 2017年11月1日下午3:51:08
 * @param src
 * @param angel
 * @return
 */
 public static BufferedImage rotate(Image src, int angel) { 
  int src_width = src.getWidth(null); 
  int src_height = src.getHeight(null); 
  // calculate the new image size 
  Rectangle rect_des = CalcRotatedSize(new Rectangle(new Dimension( 
    src_width, src_height)), angel); 
 
  BufferedImage res = null; 
  res = new BufferedImage(rect_des.width, rect_des.height, 
    BufferedImage.TYPE_INT_RGB); 
  Graphics2D g2 = res.createGraphics(); 
  // transform 
  g2.translate((rect_des.width - src_width) / 2, 
    (rect_des.height - src_height) / 2); 
  g2.rotate(Math.toRadians(angel), src_width / 2, src_height / 2); 
 
  g2.drawImage(src, null, null); 
  return res; 
 }
 
 /**
 * 計(jì)算旋轉(zhuǎn)參數(shù)
 * make by dongxh 2017年11月1日下午3:51:29
 * @param src
 * @param angel
 * @return
 */
 public static Rectangle CalcRotatedSize(Rectangle src, int angel) { 
  // if angel is greater than 90 degree, we need to do some conversion 
  if (angel >= 90) { 
   if(angel / 90 % 2 == 1){ 
    int temp = src.height; 
    src.height = src.width; 
    src.width = temp; 
   } 
   angel = angel % 90; 
  } 
 
  double r = Math.sqrt(src.height * src.height + src.width * src.width) / 2; 
  double len = 2 * Math.sin(Math.toRadians(angel) / 2) * r; 
  double angel_alpha = (Math.PI - Math.toRadians(angel)) / 2; 
  double angel_dalta_width = Math.atan((double) src.height / src.width); 
  double angel_dalta_height = Math.atan((double) src.width / src.height); 
 
  int len_dalta_width = (int) (len * Math.cos(Math.PI - angel_alpha 
    - angel_dalta_width)); 
  int len_dalta_height = (int) (len * Math.cos(Math.PI - angel_alpha 
    - angel_dalta_height)); 
  int des_width = src.width + len_dalta_width * 2; 
  int des_height = src.height + len_dalta_height * 2; 
  return new Rectangle(new Dimension(des_width, des_height)); 
 } 
 
 /**
 * 獲得圖片調(diào)整角度
 * make by dongxh 2017年11月1日下午3:40:20
 * @param imgFile
 * @return
 */
 public static Integer getImgRotateAngle(String imgFile){
 Integer angel = 0;
 Metadata metadata = null;
 try{
 if(StringUtils.isBlank(imgFile))return angel;
 File _img_file_ = new File(imgFile);
 if(!_img_file_.exists())return angel;
 metadata = JpegMetadataReader.readMetadata(_img_file_);
 Directory directory = metadata.getDirectory(ExifDirectory.class); 
 if(directory != null && directory.containsTag(ExifDirectory.TAG_ORIENTATION)){
 int orientation = directory.getInt(ExifDirectory.TAG_ORIENTATION);
 // 原圖片的方向信息 
    if(6 == orientation ){ 
     //6旋轉(zhuǎn)90 
     angel = 90; 
    }else if( 3 == orientation){ 
    //3旋轉(zhuǎn)180 
     angel = 180; 
    }else if( 8 == orientation){ 
    //8旋轉(zhuǎn)90 
     angel = 270; 
    } 
 }
 }catch(Exception e){
 e.printStackTrace();
 }
 return angel;
 }
 
 /**
 * 調(diào)整圖片角度
 * make by dongxh 2017年11月1日下午4:31:20
 * @param imgFile
 */
 public static void rotateImage(String imgFile){
 try {
 if(StringUtils.isBlank(imgFile)){
 File _img_file_ = new File(imgFile);
 if(_img_file_.exists()){
  Integer angel = getImgRotateAngle(imgFile);
  if(angel==0)return;
  BufferedImage src = ImageIO.read(_img_file_); 
  BufferedImage des = rotate(src, angel); 
  ImageIO.write(des,"jpg", _img_file_);
 }
 }
 } catch (IOException e) {
 e.printStackTrace();
 }
 }
 
 public static void main(String[] args)throws Exception{
 String fromPic = "d://88888//IMG_20171004_122718.jpg";
 //rotateImage(file);
 
 Integer angel = getImgRotateAngle(fromPic);
 System.out.println(angel);
 Thumbnails.of(fromPic)
  .rotate(angel) 
  .scale(0.2f)
  .outputFormat("jpg")
  .outputQuality(0.2f)
  .toFile(fromPic);
 
 System.out.println("==End==");
 }
 
} 

獲得圖片使用metadata-extractor

<dependency>
 <groupId>com.drewnoakes</groupId>
 <artifactId>metadata-extractor</artifactId>
 <version>2.4.0-beta-1</version>
</dependency>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • SpringBoot如何讀取resources目錄下的文件

    SpringBoot如何讀取resources目錄下的文件

    這篇文章主要介紹了SpringBoot如何讀取resources目錄下的文件問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • 淺析java中的取整(/)和求余(%)

    淺析java中的取整(/)和求余(%)

    這篇文章主要介紹了淺析java中的取整(/)和求余(%),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • Mybatis執(zhí)行多條語句/批量更新方式

    Mybatis執(zhí)行多條語句/批量更新方式

    這篇文章主要介紹了Mybatis執(zhí)行多條語句/批量更新方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • Spring Data JPA實(shí)現(xiàn)分頁P(yáng)ageable的實(shí)例代碼

    Spring Data JPA實(shí)現(xiàn)分頁P(yáng)ageable的實(shí)例代碼

    本篇文章主要介紹了Spring Data JPA實(shí)現(xiàn)分頁P(yáng)ageable的實(shí)例代碼,具有一定的參考價(jià)值,有興趣的可以了解一下
    2017-07-07
  • Java中do-while循環(huán)的使用方法及注意事項(xiàng)詳解

    Java中do-while循環(huán)的使用方法及注意事項(xiàng)詳解

    這篇文章主要介紹了Java中do-while循環(huán)的使用方法及注意事項(xiàng)的相關(guān)資料,在Java編程中,do-while循環(huán)是一種基本的循環(huán)控制結(jié)構(gòu),它至少執(zhí)行一次循環(huán)體,然后根據(jù)條件判斷是否繼續(xù),文中將用法介紹的非常詳細(xì),需要的朋友可以參考下
    2024-10-10
  • Spring集成Struts與Hibernate入門詳解

    Spring集成Struts與Hibernate入門詳解

    這篇文章主要給大家介紹了關(guān)于Spring集成Struts與Hibernate的相關(guān)資料,文中介紹的非常詳細(xì),對大家具有一定的參考價(jià)值,需要的朋友們下面來一起看看吧。
    2017-03-03
  • 詳細(xì)介紹Java關(guān)鍵字throw?throws?Throwable的用法與區(qū)別

    詳細(xì)介紹Java關(guān)鍵字throw?throws?Throwable的用法與區(qū)別

    這篇文章主要介紹了java中throws與throw及Throwable的用法和區(qū)別,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-04-04
  • 不使用myeclipse注冊機(jī)得到myeclipse注冊碼的方法(myeclipse序列號)

    不使用myeclipse注冊機(jī)得到myeclipse注冊碼的方法(myeclipse序列號)

    本文為大家介紹不使用myeclipse注冊機(jī)就能得到myeclipse注冊碼(序列號)的方法, 運(yùn)行下面的JAVA代碼就可以了
    2014-01-01
  • java調(diào)用openoffice將office系列文檔轉(zhuǎn)換為PDF的示例方法

    java調(diào)用openoffice將office系列文檔轉(zhuǎn)換為PDF的示例方法

    本篇文章主要介紹了java使用openoffice將office系列文檔轉(zhuǎn)換為PDF的示例方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。
    2017-11-11
  • java中的String定義的字面量最大長度是多少

    java中的String定義的字面量最大長度是多少

    這篇文章主要介紹了java中的String定義的字面量最大長度是多少,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12

最新評論

常德市| 高邑县| 河源市| 房产| 临潭县| 搜索| 古浪县| 宁德市| 武邑县| 嘉荫县| 浑源县| 宜宾市| 砚山县| 洪洞县| 宜州市| 浏阳市| 孝义市| 泗洪县| 通山县| 涞源县| 庆云县| 永德县| 石狮市| 集安市| 平安县| 介休市| 佛山市| 南充市| 梧州市| 清镇市| 长兴县| 博客| 通城县| 石楼县| 沾益县| 五台县| 新源县| 大名县| 安阳市| 扎鲁特旗| 靖江市|