我正在使用库通用图像加载器来显示图片。它正在工作,我在listview的每个项目中都有我的照片。我有:
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getContext()).build();
ImageLoader.getInstance().init(config);
DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisc(true).build();
ImageLoader.getInstance().displayImage(imageUri, imgView, options);
但是我想将这张照片保存在像'Bitmap myImage'这样的位图中,我该怎么做?
thx,
答案 0 :(得分:1)
更改
ImageLoader.getInstance().displayImage(imageUri, imgView, options);
到
ImageLoader.getInstance().displayImage(imageUri, imgView, options,new ImageLoadingListener()
{
@Override
public void onLoadingStarted(String arg0, View arg1)
{
}
@Override
public void onLoadingFailed(String arg0, View arg1, FailReason arg2)
{
}
@Override
public void onLoadingComplete(String arg0, View arg1, Bitmap arg2)
{
// arg2 will give you the Bitmap you want
}
@Override
public void onLoadingCancelled(String arg0, View arg1)
{
}
});
如果从提供的URL
成功下载图片,则会调用onLoadingComplete
,您将能够以Bitmap
答案 1 :(得分:0)
试试这个。你可以在位图中获取图像。
Bitmap bitmap = null;
URL imageUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) imageUrl.openConnection();
conn.setConnectTimeout(30000);
conn.setReadTimeout(30000);
conn.setInstanceFollowRedirects(true);
InputStream is = conn.getInputStream();
OutputStream os = new FileOutputStream(f);
Util.CopyStream(is, os);
os.close();
bitmap = decodeFile(f);