Java 处理图片翻转 orientation

Posted by wxianfeng Sat, 21 Jun 2014 08:22:00 GMT

首先要理解 exif orientation 概念。非常重要,这个Orientation值提供了想要正常观看图像时应该旋转的方式。

例如 iPhone 正常观看是 Home 在右,横拍

Java 自动翻转处理代码,借助 thumbnailator 库实现:


  <version>[0.4, 0.5)</version>


public static BufferedImage getImageFromUrl(String url) throws Exception {
    try {
        HttpClient client = HttpClientUtil.getHttpClient();
        HttpGet get = new HttpGet(url);

        HttpResponse response = client.execute(get);
        if (response.getStatusLine().getStatusCode() != 200) {

        // return;
        // auto rotate image orientation
        return Thumbnails.of(response.getEntity().getContent()).scale(1).asBufferedImage();
    } catch (IOException e) {
        throw new IOException("getImageFromUrl Error");

This entry was posted on Sat, 21 Jun 2014 08:22:00 GMT and Posted in . You can follow any any response to this entry through the Atom feed. You can leave a comment or a trackback from your own site.

Tags , ,


Use the following link to trackback from your own site:


Leave a comment