Thursday, July 29, 2010

[android-developers] Re: What is the best way to handle Images?

if you are hanging onto a copy of the images have a look at
SoftReference e.g.

SoftReference<Bitmap> myImage;

This will automatically handle releasing the Bitmap if it's not in use
or is taking up too much room.

If you have a set of images the best approach is a hash map where the
url of the image is the key.

This might help -
http://code.google.com/p/android-pinch/source/browse/trunk/src/com/nikkoaiello/mobile/android/WebImageView.java?r=7

Also try some housekeeping things like closing any streams.

Ed

On Jul 30, 12:42 am, Sohan badaya <sohan.bad...@gmail.com> wrote:
> Hi All,
>
> I wrote a application that load images from facebook and i show in
> lmageview, using this below code.
>
>                                 InputStream object = myDataFromServer;
>                                 Bitmap bmpImage=BitmapFactory.decodeStream(object);
>                                 imageView.setImageBitmap(bmpImage);
>
> it works fine for me. But the trouble is when i run my application for
> a longer time, it gives me error,
> OutofMemoryError, and becuse of this error my application crash.
>
>       so want to know is there any better way to handling
> images.please help me.
>
> Thanks,
> Sohan Badaya

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate