Hi, there!

I am so strange. Please help me!
I drawn a large bitmap(4500X1200px) and many small bitmaps -there are
must be drawn on the large bitmap using same canvas. (Like map and
pins) All images are downloaded and cached.
I implemented an image cache with SoftReference and draw Bitmaps from
the image cache. I need use its cached bitmaps in the many activities.
Also I copied large bitmap.I have to set true to isMutable.
The first time, it is displayed well. When I try to redraw or go to
other screens, Out of Memory error occurs.
I do not use Bitmap.recycle() before setting the bitmaps. Because
after recycling, "RuntimeException: Canvas: trying to use a recycled
bitmap" exception occurs.

I think that Garbage Collector can't remove cached bitmaps.  Should
not I use image cache? i think that if i do not use image cache,  it
will decrease the performance. What should I do? Please help me.

======================= MapPin class
public class MapPin {
        public Bitmap bitmap;
....
        //URLからアイコンを表示する。サイズ:72X72(pixelで)
        bitmap  = ImageCache.getImage(imgUrl);
        if (bitmap == null) {
             bitmap = HttpClient.getImage(imgUrl, context);
             ImageCache.setImage(imgUrl, bitmap);
        }
    public void draw(Canvas canvas){
        if(bitmap != null){
                int dWidth = bitmap.getWidth()/2;
                int dHeight = bitmap.getHeight()/2;
                canvas.drawBitmap(bitmap, left-dWidth, top -dHeight, null);
        }
    }
}

========= in My Activity
//icon list of map
                List<MapPin> mapPinList;
                for(int indx=0; indx<mapPinList.size(); indx++){
                        MapPin temp= new MapPin();
                        
temp.setBitMap(this.context,mapPinList.get(indx).iconUrl);

                }
// map image
                Bitmap floorMapImg = ImageCache.getImage(floorMapUrl);
                if (floorMapImg == null) {
                        floorMapImg =
HttpClient.getImage(mapList.get(defaultMapIndx).floorMapUrl, this);
        
ImageCache.setImage(mapList.get(defaultMapIndx).floorMapUrl,
floorMapImg);
                }
                floorMapImg = floorMapImg.copy(Bitmap.Config.RGB_565, true);

//draw icons
                Canvas canvas = new Canvas(floorMapImg);
                for(int indx=0; indx < mapPinList.size(); indx++){
                        mapPinList.get(indx).draw(canvas);
                }


Thanks!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to