从互联网地址加载图片,有些图片会被旋转90度。

3
如何判断从url加载的图片是否旋转?
我有一组来自url的图片列表,其中有些加载的图片与原始图片相比旋转了90度。

如果它们是JPEG格式的,则查找EXIF“方向”标头。像BitmapFactory这样的原始Android代码会忽略此标头,但某些图像加载库可能会注意到该标头(例如Picasso)。 - CommonsWare
1个回答

0

这里有一个代码。如果你的图片是横向模式,它将重新定位你的图片:

int width = bitmap.getWidth();
int height = bitmap.getHeight();

if (width > height){
    rotatedBitmap = rotate(bitmap,-90)
}


private Bitmap rotate(Bitmap bm, int rotation) {
    if (rotation != 0) {
        Matrix matrix = new Matrix();
        matrix.postRotate(rotation);
        Bitmap bmOut = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);
        return bmOut;
    }
    return bm;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接