java实现图片转向处理-创新互联
引入maven
创建工具类:
public class ImageUtil {
public static int getRotateAngleForPhoto(File file) {
int angel = 0;
try {
//核心对象操作对象
Metadata metadata = ImageMetadataReader.readMetadata(file);
//获取所有不同类型的Directory,如ExifSubIFDDirectory, ExifInteropDirectory, ExifThumbnailDirectory等,这些类均为ExifDirectoryBase extends Directory子类
//分别遍历每一个Directory,根据Directory的Tags就可以读取到相应的信息
int orientation = 0;
Iterable
for (Iterator
Directory dr = iter.next();
if (dr.getString(ExifIFD0Directory.TAG_ORIENTATION) != null) {
orientation = dr.getInt(ExifIFD0Directory.TAG_ORIENTATION);
}
Collection
for (Tag tag : tags) {
System.out.println(tag.getTagName() + ": " + tag.getDescription());
}
}
if (orientation == 0 || orientation == 1) {
angel = 360;
} else if (orientation == 3) {
angel = 180;
} else if (orientation == 6) {
angel = 90;
} else if (orientation == 8) {
angel = 270;
}
} catch (Exception e) {
e.printStackTrace();
}
return angel;
}
}
创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。
分享题目:java实现图片转向处理-创新互联
当前URL:http://pwwzsj.com/article/jcghd.html