将文件对象转换为位图 [英] Convert a File Object to Bitmap
本文介绍了将文件对象转换为位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Universal-Image-Loader,并且具有此功能,可从sd卡访问图像的文件缓存.但是我不知道如何将返回的文件缓存转换为位图.基本上,我只是想将位图分配给ImageView.
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);
错误:"ImageView类型的setImageBitmap(Bitmap)方法不适用于参数(文件)"
推荐答案
您应该可以使用BitmapFactory
:
File mSaveBit; // Your image file
String filePath = mSaveBit.getPath();
Bitmap bitmap = BitmapFactory.decodeFile(filePath);
mImageView.setImageBitmap(bitmap);
这篇关于将文件对象转换为位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文