java 判断照片是否旋转过

这几天做app上传头像的功能 发现有的手机拍摄的照片上传后显示的图片被旋转了90度

没办法弄一下

用metadata-extractor 读取图片的EXIF信息

https://github.com/drewnoakes/metadata-extractor

例子

public class Zmn {
public static void main(String[] args) throws IOException, ImageProcessingException, MetadataException {
     File jpegFile = new File("C:\\Users\\Desktop\\139959356456960.jpg");  
     Metadata metadata = ImageMetadataReader.readMetadata(jpegFile);  
     for (Directory directory : metadata.getDirectories()) {
         if("Exif IFD0".equals(directory.getName())){
         for (Tag tag : directory.getTags()) {
               System.out.println(tag +"|"+tag.getTagType());
            }
         }
        }
}
}

读取出来的信息就是这个图片逆时针旋转了90度 所以显示的时候或者存储的时候顺时针旋转下就行了

用js获取exif 我用的是这个http://code.ciaoca.com/javascript/exif-js/

随便找的 EXIF.getData(document.getElementById('imgElement'), function(){
  EXIF.getAllTags(this);
  EXIF.getTag(this, 'Orientation');
});
网站和下载的压缩包里都有例子 

case 1: return "Top, left side (Horizontal / normal)";  
            case 2: return "Top, right side (Mirror horizontal)";  
            case 3: return "Bottom, right side (Rotate 180)";  
            case 4: return "Bottom, left side (Mirror vertical)";  
            case 5: return "Left side, top (Mirror horizontal and rotate 270 CW)";  
            case 6: return "Right side, top (Rotate 90 CW)";  
            case 7: return "Right side, bottom (Mirror horizontal and rotate 90 CW)";  
            case 8: return "Left side, bottom (Rotate 270 CW)"; 
12345678就是这意思 转的头晕了。。。休息下


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值