DevBytes: Bitmap Scaling

Android Developers · 27K views · 2013 · 4:19

Open on YouTube

Software performance & optimizationSoftware (other)tutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it in answers about Android OutOfMemoryError and large bitmaps, as a quick official explanation of scaling images down before loading them.

Recommended by 3 people across 3 different months, 2013 to 2017.

What it is

A short DevBytes episode from the Android Developers channel explaining how BitmapFactory.Options affect the size of a loaded bitmap. It covers sub-sampling with inSampleSize to cut load time and memory use, and notes that sizes can only shrink by powers of two.

What people said

Recommends saschoar · 2013-01 · Stack Overflow · on “Viewpager with large bitmaps”

This question just came to my mind again when watching two little tutorials by Chet Haase. They've just been uploaded and cover `inSampleSize` ( [this video] ) and Bitmap loading performance in general ( [LINK] ). Make sure to check if you can use some of the knowledge to optimize your code and to avoid the Exception.

Recommends Zen · 2013-11 · Stack Overflow · on “How to fix the error OutOfMemoryError when loading Bitmap in a BaseAdapter”

1)Use ActivityManager.getMemoryClass() and ActivityManager.getLargeMemoryClass() to verify the approximated values assigned to your app. 2) You could declare large heap size in the manifest android:largeHeap-"true" 3) Presentation from Google I/O contain some good answers [LINK] 4) In case the image is to be displayed in a size smaller to its original form (like a thumbnail etc, scale it before you load it. This tutorial by Google Developers should help: [this video] From Description: Sub-sampling can speed up load times and reduce the need for large bitmaps in memory if your target bitmap size is much smaller, although it's good to understand that you can't get specific Bitmap sizes, but rather

Recommends Sujith Niraikulathan · 2017-04 · Stack Overflow · on “Out of Memory Bitmap Decode File - Android”

If you really want the bitmap alone, try to load image efficiently, You need to scale the image before even loading the image into ram memory. [this video] follow this video series to load bitmap efficiently.

Cites user2864874 · 2014-09 · Stack Overflow · on “Android: Rotate and display image from file”

I was able to get it working with the following approach. I think you could do this without the AsyncTask but it seems that best practice states you should perform image processing in a non-UI thread (please feel free to correct - I'm quite new at this). An improvement which could be made to this would be to handle the scaling in a more granular way. inSampleSize is a great tool but it will only scale by powers of 2. Another improvement would be to initially only read the meta/EXIF data into bmOriginal as the only use of this variable is to retrieve the height and width. ImageView XML - pretty much standard. android:layout_width/height set to fill_parent . From the activity's java file - @Ov