我需要使用相机拍照,并在将其保存到图库之前根据图片大小旋转它。
我正在使用以下方法:
Intent imageCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); imageCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri); startActivityForResult(imageCaptureIntent, IMAGE_CAPTURE);
用于拍照并将其保存到临时文件中。
然后是
Bitmap bmp = BitmapFactory.decodeFile(imagePath);
String str = android.provider.MediaStore.Images.Media.insertImage(cr, bmp, name, description);
用于保存它。
这是我尝试使用的代码来旋转位图:
Matrix matrix = new Matrix();
matrix.postRotate(180);
Bitmap x = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
android.provider.MediaStore.Images.Media.insertImage(cr, x, name, description);
问题是我得到了一个OutOfMemoryException。
有什么更好的方法来处理位图,以避免内存破裂吗?
提前感谢您的帮助,祝好!