开发者

BitmapFactory decode function for Android

I encounter problem with .decodeStream function.

File cacheMap = new File(context.getCacheDir(), "test.GIF");

if(cacheMap.exist()){
    FileInputStream is = new FileInputStream(cacheMap);
    Bitmap bitmap = BitmapFactory.decodeStream(is);
    puzzle.add(test);
}else{
 //retrieved from server and cache the image
}

The decode function always return null value. And from the internet, I found that in order to display the image, the Bitmap is always set to an ImageView. But what I am doing here is storing it into a ArrayList of Bitmap and display it later on in a Canvas. Can anyone tell me how to get back the image after decoding it?

From this page, it states the following,

public static Bitmap decodeStream (InputStream is)

Decode an input stream into a bitmap. If the input stream is null, or cannot be used to decode a bitmap, the function returns null. The stream's position will be where ever it was after the encoded data was read.

Parameters: The input stream that holds the raw data to be decoded into a bitmap.

Returns:The decoded bitmap, or null if the 开发者_高级运维image data could not be decoded."

Does it means that the image that was cached previously cannot be use to decode it even though I had run the few line of code to cached the image?

cacheMap.createNewFile();
fos = new FileOutputStream(cacheMap);
bitmap.compress(CompressFormat.JPEG, 100, fos);
fos.flush();       
fos.close(); 

Does anyone know what is wrong with my code? i have been tackling this issue for days and is driving me crazy!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜