我的应用程序中也有同样的问题。下面的解决方案对我来说工作得很好,希望它也能帮助你。
添加按照您的OnActivityResult
方法的代码,
Bitmap imgTemp = null;
String path = mImageCaptureUri.getPath();
if(imgTemp != null && !imgTemp.isRecycled())
{
imgTemp.recycle();
imgTemp = null;
}
BitmapFactory.Options options = new BitmapFactory.Options();
options.inDither = false;
options.inPurgeable = true;
options.inInputShareable = true;
options.inTempStorage = new byte[10*1024];
imgTemp = BitmapFactory.decodeFile(path,options);
imgTemp = Bitmap.createScaledBitmap(imgTemp, 480, 800, true);
ExifInterface ei = new ExifInterface(path);
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
imgTemp = rotateImage(imgTemp, 90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
imgTemp = rotateImage(imgTemp, 180);
break;
// etc.
}
这里,mImageCaptureUri是URI由摄像机拍摄的图像。
而且也是你的活动添加方法rotateImage
,
public Bitmap rotateImage(Bitmap source, float angle)
{
Matrix matrix = new Matrix();
matrix.postRotate(angle);
return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}
你的意思是你拍摄的图像结果为旋转吗? – AndyN
是它始终在旋转@ N2P –
@MuhammadUmar看到我的答案,它肯定会解决您的问题 –