Performance optimisations for android applications - Part 3 BitmapFactory.Options inSampleSize

preview_player
Показать описание
Part 3 - Uses the BitmapFactory.Options inSampleSize to subsample the original image therefore loading a smaller image saving memory & cpu resources, resulting in more responsiveness especially in scrolling.

These tutorials are expected to be viewed in sequence starting from Part 1 & Part 2.

In this part of the android tutorial performance series we identify one of the main performance issues is with loading the full size images straight into the much smaller ImageViews thumbnails.

The result is to create a scale factor algorithm to measure the difference in width & height between the image & ImageView and output that result as a factor of 2.
This can then be feed into the BitmapFactory.Options inSampleSize where subsampling can then take place resulting the loading of a smaller image.

All this happens in a background thread created by a AsyncTask.

In this tutorial we will cover:
- Creating the scale factor algorithm
- Getting the image dimensions from inJustDecodeBounds to true
- Calling the scale factor algorithm
- Setting the inSampleSize prior to loading the image
- Run the application and check for performance changes
- Debug app and step through the code changes

The previous tutorials were aimed at beginners to android but over time have been getting more complex as the original camera_intent app has developed.
This tutorial series is more aimed towards the intermediate developers but for those who have been following the previous tutorial series, feel free to watch this android performance series.

Android studio (1.2.1) is the editor of choice (IDE) for this tutorial series.

API's covered
- BitmapFactory.Options
- BitmapFactory.Options inJustDecodeBounds
- BitmapFactory.Options inSampleSize
- BitmapFactory.DecodeFile

This tutorial series is the start of what I expect to be many so I encourage comments and feedback to improve the quality and viewing experience.
Рекомендации по теме
Комментарии
Автор

Use cmd + D to duplicate lines. Much faster than typing the same code again and again. Thank you for this video.

guillaumeleroy
Автор

I'm new to Android development but I have an app that generates OOMs ( Out Of Memory ) errors when accessing certain activities.

I did a lot of searching and discovered InSampleSize; however, I could not figure out how to use or implement it so I could change image size being loaded on the fly.

I just discovered this video by searching for InSampleSize and it looks like I'll be able to solve my issues with OOMs by decoding images before they are loaded.

Would it be better to just resize the images to be smaller up front?

Why and When should one use these routines and methods that will be presented here.

Apologize as I've not watched first two videos.

Thanks in advance for all input and suggestions...

Thanks for creating and sharing this video.

I'm going to watch it now...

Thankful_n_Grateful
Автор

There are 10 types of programmers...​ Those who fix compile errors right away, and those that don't.

gosnooky
Автор

Great video Nigel!!! I have a little question, when I use Thumbnails to get the preview of the image, the image is rotated 90 degrees clockwise, is that normal?

Themusicaligera
Автор

I have a little question, i dont have a file path on the method decodeBitmapFromFile, I receive an uri sent by the intent of ACTION_IMAGE_CAPTURE, how can I use the this Uri as a parameter instead of your ¨File imageFile¨ as the received parameter?

Themusicaligera
join shbcf.ru