目標:我想發送所拍攝的圖像文件服務器,在代碼中,我可以通過改造發送photoFile
到服務器上,但圖像是在服務器端的轉動,所以我的目標是觀察旋轉,旋轉回到真實狀態並將該文件發佈到服務器。的OutOfMemoryError錯誤而旋轉的位圖
問題:我從凸輪捕捉圖像,然後觀察它的旋轉,並基於此旋轉,但它在創建第二個旋轉的位圖時發生內存不足錯誤。
問題:我正在尋找解決方案,我可以在不創建位圖的情況下將其發送到服務器,如果沒有,避免發生內存異常並將正確旋轉的文件發送到服務器。
else if (requestCode == CAPTURE_IMAGE) {
ExifInterface exifInterface = new ExifInterface(photoFile.getAbsolutePath());
Bitmap bitmapOrg = BitmapFactory.decodeFile(photoFile.getAbsolutePath(), new BitmapFactory.Options());
Matrix matrix = new Matrix();
//getRotation method rightly gives 90 as rotation.
matrix.postRotate(getRotation(exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL)));
//point of outofmemory error while creating this bitmap
Bitmap rotated = Bitmap.createBitmap(bitmapOrg, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
Log.d(TAG, "onActivityResult: ");
}
你不需要創建位圖。使用ExifInterface在文件中設置正確的旋轉。閱讀exif。將旋轉設置爲想要的。寫exif回來。 – greenapps