カメラから撮った画像を回転させて、ビューに表示せずに縮小せずに保存しようとしていますが、このようにロードしようとすると
Bitmap bmp = BitmapFactory.decodeFile(tmpImageFilePath);
OutOfMemoryErrorが発生します。画像を回転させても問題ありませんが、画像を読み込んで元のサイズで保存するにはどうすればよいですか?私はこの問題を解決するためにすでにいくつかのテクニックをグーグルで検索しましたが、どれも私には合いません。
そして、私がこの変種を試してみると:
File f = new File(tmpImageFilePath);
long filesize = f.length();
ExifInterface exif = new ExifInterface(f.getPath());
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
int angle = 0;
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
angle = 90;
}
else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
angle = 180;
}
else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
angle = 270;
}
Matrix mat = new Matrix();
mat.postRotate(angle);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
Bitmap bmp = BitmapFactory.decodeFile(tmpImageFilePath, options);
Bitmap correctBmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), mat, true);
bmp.recycle();
try {
FileOutputStream out = new FileOutputStream(f);
correctBmp.compress(Bitmap.CompressFormat.JPEG, 90, out);
} catch (Exception e) {
e.printStackTrace();
}
画像が少なくなります。