您的位置:首页 > 其它

关于从相册取出图片后,图片不能按原来角度显示的问题解决方案

2013-04-17 17:01 796 查看
(在F:\java\心情秀)

1、取得图片本身的角度
/**
* 获得图片的角度进行修正
*/
private int readPicDegree(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;

default:
break;
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
Log.i(TAG, "ct test------------------>degree "+degree);
return degree;
}


相关链接:http://blog.csdn.net/liuhanhan512/article/details/8277637

2、获得计算好的insamples的图片

private Bitmap getSrcPic(String path){
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);

bitWidth = options.outWidth;
bitheight = options.outHeight;

while ((bitWidth / sampleSize > DEFAULT_WIDTH * 2) || (bitheight / sampleSize > DEFAULT_HEIGHT * 2)) {
sampleSize *= 2;
}
options.inJustDecodeBounds = false;
options.inSampleSize = sampleSize;
Bitmap bitmap = BitmapFactory.decodeFile(path, options);
return bitmap;
}


相关链接:/article/5641917.html

3、对图片进行旋转

private Bitmap rotateBitmap(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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐