Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Resize a large bitmap file to scaled output file
    primarykey
    data
    text
    <p>I have a large bitmap (say 3888x2592) in a file. Now, I want to resize that bitmap to 800x533 and save it to another file. I normally would scale the bitmap by calling <code>Bitmap.createBitmap</code> method but it needs a source bitmap as the first argument, which I can't provide because loading the original image into a Bitmap object would of course exceed the memory (see <a href="https://stackoverflow.com/questions/477572/android-strange-out-of-memory-issue">here</a>, for example).</p> <p>I also can't read the bitmap with, for example, <code>BitmapFactory.decodeFile(file, options)</code>, providing a <code>BitmapFactory.Options.inSampleSize</code>, because I want to resize it to an exact width and height. Using <code>inSampleSize</code> would resize the bitmap to 972x648 (if I use <code>inSampleSize=4</code>) or to 778x518 (if I use <code>inSampleSize=5</code>, which isn't even a power of 2).</p> <p>I would also like to avoid reading the image using inSampleSize with, for example, 972x648 in a first step and then resizing it to exactly 800x533 in a second step, because the quality would be poor compared to a direct resizing of the original image.</p> <p>To sum up my question: Is there a way to read a large image file with 10MP or more and save it to a new image file, resized to a specific new width and height, without getting an OutOfMemory exception?</p> <p>I also tried <code>BitmapFactory.decodeFile(file, options)</code> and setting the Options.outHeight and Options.outWidth values manually to 800 and 533, but it doesn't work that way.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload