2016-04-23 36 views
1

如何识别图像加载从URL被旋转?加载从互联网网址的图像,有些旋转90度

我有一个来自url的图像列表,一些加载的图像与原始图像相比旋转了90度。

+0

如果它们是JPEG,请查找EXIF'方向'标题。股票的Android代码,比如'BitmapFactory',忽略了这一点,尽管一些图片加载库可能会关注这个头文件(毕加索?)。 – CommonsWare

回答

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; 
}