Android: rotate image without loading it to memory

后端 未结 6 1971
梦谈多话
梦谈多话 2020-11-28 08:09

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

The reason is why I am looking for that is famous OutOfMemoryError

6条回答
  •  旧巷少年郎
    2020-11-28 08:59

    you should decode decode the images using Bitmap. 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..

    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);
    

    with the attribute ExifInterface.TAG_ORIENTATION I hope this helps you

提交回复
热议问题