今天遇到一个奇怪的现象 就是三星Note3 7508v型号的手机 拍照后 会自动的进行翻转。
1 代码中处理
int degree = CommonUtils.getBitmapDegree(arg0.result.toString());
if(degree>0 ){BitmapFactory.Options opts=new BitmapFactory.Options();//获取缩略图显示到屏幕上
opts.inSampleSize=10;
Bitmap cbitmap=BitmapFactory.decodeFile(arg0.result.toString(),opts);
/**
* 把图片旋转为正的方向
*/
Bitmap newbitmap =CommonUtils.rotaingImageView(degree, cbitmap);
imageHolder.image.setImageBitmap(newbitmap);
}else {
bitmapUtils
.display(imageHolder.image,arg0.result.toString());
}
imageHolder.image.setOnClickListener(new ImageClickLisenter(
arg0.result.toString()));
imageHolder.pic_progress.setVisibility(View.GONE);
imageHolder.image.setAlpha(1f);
2 工具类中的处理:
CommonUtils 工具类中的方法 。
/**
* 图片旋转
* @param angle
* @param bitmap
* @return
*/
public static Bitmap rotaingImageView(int angle, Bitmap bitmap) {
// 旋转图片 动作
Matrix matrix = new Matrix();
;
matrix.postRotate(angle);
// 创建新的图片
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
bitmap.getWidth(), bitmap.getHeight(), matrix, true);
return resizedBitmap;
}
/**
* 读取图片的旋转的角度
*
* @param path
* 图片绝对路径
* @return 图片的旋转角度
*/
public static int getBitmapDegree(String path) {
int degree = 0;
try {
// 从指定路径下读取图片,并获取其EXIF信息
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;
}