我的應用程序中也有同樣的問題。下面的解決方案對我來說工作得很好,希望它也能幫助你。
添加按照您的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看到我的答案,它肯定會解決您的問題 –