Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest way to read/write a Bitmap from/to file?

I'm currently writing Bitmaps to a png file and also reading them back to a Bitmap. I'm looking for ways to improve the speed at which writing and reading happens. The images need to be lossless since I'm reading them back to edit them.

The place where I see the worst performance is the actual BitmapFactory.decode(...).

Few questions:
1. Is there a faster solution to read/write from file to a Bitmap using NDK?
2. Is there a better library to decode a Bitmap faster?
3. What is the best way to store and read a Bitmap?

like image 570
Jona Avatar asked Apr 29 '12 23:04

Jona


1 Answers

Trying to resolve the best/fastest possible way to read/write image to file came down to using plain old BitmapFactory. I have tried using NDK to do the encoding/decoding but that really didn't make a difference.

Essentially the format to use was lossless PNG since I didn't want to loose any quality after editing an image.

The main concept from all this was that I needed to understand was how long encoding took versus decoding. The encoding numbers where in the upper 300-600ms, depending on image size, and decoding was just fast, around 10-23ms.

After understanding all that I just created a worker thread that I passed images needing encoding and let it do the work without affecting the user experience. The image was kept cached in memory just in case it was needed right away before it was completely encoded and saved to file.

like image 87
Jona Avatar answered Sep 19 '22 17:09

Jona