解决三星手机拍照默认横屏问题

博客园第一天,发一个今天发现的问题吧。

今天在开发android的时候发现一个问题,三星和联想手机的系统拍照功能默认横屏拍照。拍出来的照片也是横屏,所以在页面上的展示也是横屏,与实际相反。

查资料后发现这是手机厂商的问题,从代码端无法决定横屏拍还是竖屏拍。

 

最后我的解决办法是手动判断照片是横向还是竖向(即照片的偏离角度),主要代码如下:

/**
* 读取图片属性:旋转的角度
* @author GuoJing
* @param path
* 图片绝对路径 degree旋转的角度
*/
public static int readPictureDegree(String path) {
int degree = 0;
try {
ExifInterface exifInterface = new ExifInterface(path);
int orientation = exifInterface.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
degree = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
degree = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
degree = 270;
break;
}
} catch (IOException e) {
e.printStackTrace();
}
return degree;
}

 

然后根据偏离的角度去手动旋转图片然后上传,相关代码如下:

Matrix matrix = new Matrix();
matrix.reset();
matrix.setRotate(FileUtil.readPictureDegree(path));
bitmap = Bitmap.createBitmap(bitmap,0,0, bitmap.getWidth(), bitmap.getHeight(),matrix, true);

 

 

最后该问题完美解决。

 

posted @ 2015-04-20 17:00  天津大学  阅读(5844)  评论(0编辑  收藏  举报