开发者

Loading images from cache but return a blank screen

i try the example i gotten from here. The example shows how to display a image that is larger then the screen and the screen acting like a window, allowing user to look at the images via scrolling. However, what i want to achieved is similar just that, instead of one single image, i tried to combining 18 smaller images (171X205) into one single image. I am able to did that but to save loading time on downloading of images from the server, i cached the images. Heres the problem, i cant seems to display the images out on screen even though the images are indeed cached. Thus, i tried something else by fetching image from the drawable folder but still the same issue arise. Does anyone have any idea how to go about solving this problem?

A snippets of code to load images from cache:

for(int i =0; i<18; i++)
    File cacheMap = new File(context.getCacheDir(), smallMap开发者_开发问答ImageNames.get(i).toString());
            if(cacheMap.exists()){
                //retrieved from cached
                    try {
                        FileInputStream fis = new FileInputStream(cacheMap);
                        Bitmap bitmap = BitmapFactory.decodeStream(fis)
                        puzzle.add(bitmap);
                     }catch(...){}
             }else{
                 Drawable smallMap = LoadImageFromWebOperations(mapPiecesURL.get(i).toString());
                if(i==0){
                    height1 = smallMap.getIntrinsicHeight();
                    width1 = smallMap.getIntrinsicWidth();
                }
                if (smallMap instanceof BitmapDrawable) { 
                    Bitmap bitmap = ((BitmapDrawable)smallMap).getBitmap();
                    FileOutputStream fos = null;
                    try {
                        cacheMap.createNewFile();
                        fos = new FileOutputStream(cacheMap);
                        bitmap.compress(CompressFormat.JPEG, 100, fos);
                        fos.flush();       
                        fos.close(); 
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }       

                    puzzle.add(bitmap);
                }
             }
}

The function where it retrieved images from the server

private Drawable LoadImageFromWebOperations(String url) {
        // TODO Auto-generated method stub
        try
        {
            InputStream is = (InputStream) new URL(url).getContent();
            Drawable d = Drawable.createFromStream(is, "src name");
            return d;
        }catch (Exception e) {
            System.out.println("Exc="+e);
            return null;
        }
    }

I am drawing onto a canvas and so no ImageView is use to display the images.


For all of my lazy image loading I use Prime.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜