目标:我想发送所拍摄的图像文件服务器,在代码中,我可以通过改造发送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