Question

It seems like there are a few different ways to get a bitmap from the storage on a phone.

I'm reading the data from all the images by using a MediaStore query and I save both the path and the imageId in memory. Then later if I want to upload a small thumbnail of the image I can either:

1) query the mediastore for a micro/mini kind of thumbnail based on the image id, then create a scaled bitmap from that to fit my exact needs (if the micro/mini is not the correct size)

Bitmap bm = MediaStore.Images.Thumbnails.getThumbnail(context.getContentResolver(),     imageId, MediaStore.Images.Thumbnails.MINI_KIND, null);
Bitmap.createScaledBitmap(bm, (int)newWidth, (int)newHeight, true);

or

2) fetch the bitmap from the file location and then create a scaled bitmap from that

Bitmap bitmap = BitmapFactory.decodeFile(url);
Bitmap.createScaledBitmap(bitmap, (int)newWidth, (int)newHeight, true);

I was originally doing #1 because I figured the thumbnail generation would be quick from the mediastore which would make the createScaledBitmap process finish quicker rather than creating a scaled bitmap from the fullsize image. Is there a best way or is this difference completely negligible?

Was it helpful?

Solution

I'm not an expert, but I would think that the difference between the two would be negligible, considering that either way you're creating a scaled image. It would seem the only difference would be the time it would take to scale from thumbnail versus scale from bitmap, and either way I think you're talking about nanoseconds.

Honestly, it would seem that you would want to use #1 simply for memory use, rather than loading from full size image and then down sampling, you're loading it from the thumbnail and sizing up if necessary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top