... // determine the width/height or a gallery item's view
Rect rectOfGalleryItemView = ...;
...
... // Then determine the best sampleSize (1, 2, 4, 8)
int sampleSize = calculateSampleSize(rectOfGalleryItemView, 2048,
1536);

BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inDither = true; // we're using RGB_565, dithering improves this
a bit.
opts.inPreferredConfig = Bitmap.Config.RGB_565;
opts.inSampleSize = sampleSize;
bm = BitmapFactory.decodeStream("/sdcard/dcim/Camera/" + photoList[i],
opts);

And yes, it takes a bit longer to decode here. In my app, i put
decoding the bitmap in a background thread (much like AsyncTask). But
you can cache the decoded bitmaps and be a bit smart about pre-loading
bitmaps before they become visible in the Gallery. If you use a cache,
you need to manage the cache. Clear it when memory may run low, etc.

On another note; i noticed that using an inSampleSize value of larger
than 1 produces better quality images than using createScaledBitmap.



On May 22, 9:12 am, guruk <ilovesi...@gmail.com> wrote:
> :) I got it now already up to 15 :)
>
> bm = BitmapFactory.decodeFile("/sdcard/dcim/Camera/" + photoList[i]);
> bphotos.add(Bitmap.createScaledBitmap(bm, 480, 320, true));
> bm.recycle();
>
> when I always use bm.recycle()
>
> ok, but lets look on your insamplesize... i will also try.
> but how to use in samplzesiez with decodeFile?
> finaly i need 480x320...
>
> but i am not sure if that helps at all. because life decoding needs
> quit long time. so i have 2 options. a thread with background decoding
> or creating thumbs and loading them direct into a gallery
>
> but please tell me how to use insamplesize with .decodeFile or
> creatscalebitmap
>
> greets
> chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to