Search code examples
javaandroidcachingbitmapuniversal-image-loader

Convert a File Object to Bitmap


I am using Universal-Image-Loader and there is this functionality that access the file cache of the image from sd card. But I don't know how to convert the returned file cache into bitmap. Basically I just wanted to assign the bitmap to an ImageView.

File mSaveBit = imageLoader.getDiscCache().get(easyPuzzle);

Log.d("#ImageValue: ", ""+mSaveBit.toString());
mImageView.setImageBitmap(mSaveBit);

Error: "The method setImageBitmap(Bitmap) in the type ImageView is not applicable for the arguments (File)"


Solution

  • You should be able to use BitmapFactory:

    File mSaveBit; // Your image file
    String filePath = mSaveBit.getPath();  
    Bitmap bitmap = BitmapFactory.decodeFile(filePath);
    mImageView.setImageBitmap(bitmap);