激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|JavaScript|易語(yǔ)言|

服務(wù)器之家 - 編程語(yǔ)言 - Java教程 - java實(shí)現(xiàn)圖片角度旋轉(zhuǎn)并獲得圖片信息

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

2021-07-14 16:13fackyou200 Java教程

這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)圖片角度旋轉(zhuǎn)并獲得圖片信息,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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

?
1
2
3
4
5
<dependency>
 <groupid>com.drewnoakes</groupid>
 <artifactid>metadata-extractor</artifactid>
 <version>2.4.0-beta-1</version>
</dependency>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:https://blog.csdn.net/fackyou200/article/details/78435709

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 爱高潮www亚洲精品 国产一区二区三区视频免费 | 黄色大片在线免费观看 | 国产精品久久久久av | 久久精品视频亚洲 | 国产精品99久久久久久久女警 | 国产男女 爽爽爽爽视频 | 日韩毛片在线看 | www.99热视频 | 欧美国产成人在线 | 成人福利在线播放 | 欧美一级淫片免费视频1 | 欧美一级黄色录像片 | 精品一区二区亚洲 | 欧美成人二区 | 91伊人久久 | 欧美日韩视频在线播放 | 1级黄色毛片 | 天堂精品 | 亚洲精品aⅴ中文字幕乱码 中文字幕欧美在线 | 一级毛片在线视频 | 欧美激情性色生活片在线观看 | 99视频有精品视频高清 | 一本色道久久综合亚洲精品图片 | 国产精品wwww | 一级做a爱片毛片免费 | 嫩呦国产一区二区三区av | 国产99久久久久久免费看农村 | 国产精品自拍99 | 性欧美极品xxxx欧美一区二区 | 99r国产精品 | 成人综合一区二区 | 19禁国产精品福利视频 | 亚洲第一视频在线 | 九九视频精品在线 | 日韩.www| 九九午夜 | 免费看日产一区二区三区 | 操碰97| 久久久久久麻豆 | 国产精品99久久久久久久女警 | 免费黄色在线观看网站 |