安卓:旋转图像,而无需加载到内存图像、加载、内存

2023-09-13 00:23:09 作者:孤浪

我不知道是不是可以旋转存储在SD卡的图像,而无需加载它的内存。

I am wondering is it possible to rotate an image stored on sdcard without loading it's to memory.

原因是为什么我找的就是著名的OutOfMemoryError。我知道我可以通过下采样大的图像避免,但其实我并不想以减少图像的尺寸,我想有原来的形象,但在旋转90度。

The reason is why I am looking for that is famous OutOfMemoryError. I know I can avoid it by downsampling large image but in fact I don't want to reduce size of that image, I want to have original image but rotated on 90 degrees.

有关热烈AP preciated任何建议:)

Any suggestions about that are warmly appreciated :)

推荐答案

你应该去c。使用 Bitmap`的图片code德$ C $。您应该遵循加载如何做到这一点psented由谷歌大图片 $ P $。它帮助了我很多,你会发现在内存占用较大的差异。

you should decode decode the Images usingBitmap`. you should follow Loading Large Image presented by google on how to do it.. it helped me alot, you'll notice the large difference in the RAM usage..

更新如果你想要的是只需旋转您可以使用此code图像

UPDATE if all you want is just rotate the image you can use this code

Matrix matrix = new Matrix();
matrix.setRotate(90);
result = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),bitmap.getHeight(), matrix, false);

如果你只需要设置图像方向(例如照片显示方向它拍摄的时候),可以使用

if you just need to set the image orientation (for example the photo orientation when it's was taken) you can use

ExifInterface exif = new ExifInterface(filePath);

与属性 ExifInterface.TAG_ORIENTATION 我希望这可以帮助你。

with the attribute ExifInterface.TAG_ORIENTATION I hope this helps you

 
精彩推荐
图片推荐