这几天做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就是这意思 转的头晕了。。。休息下