How to rotate JPEG images based on the orientation metadata?

后端 未结 8 1804
轻奢々
轻奢々 2020-11-27 12:30

I have some server code that is generating thumbnails when an image is uploaded. The issue is that when the image was taken and the camera/device was rotated, the thumbnail

8条回答
  •  一生所求
    2020-11-27 13:04

    As dnault mentioned in previous comment, Thumbnaliator library resolves the issue. But you should use correct input/output formats to avoid color change on this automatic rotation.

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ByteArrayInputStream in = new ByteArrayInputStream(file.getContents());
    Thumbnails.of(in)
        .scale(1)
        .toOutputStream(baos);
    byte[] bytes = baos.toByteArray();
    

提交回复
热议问题