2014-05-22 57 views
0

我使用庫通用圖像加載程序來顯示圖片。它工作正常,我在列表視圖中的每一項中都有我的照片。我有:Android通用圖像加載程序獲取圖片

 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); 

但我想將此圖片保存在位圖像'位圖myImage',我該怎麼做?

THX,

+0

你的問題不清楚,你想把圖像當成位圖嗎?你嘗試過位圖bm =((BitmapDrawable)imageView.getDrawable())。getBitmap(); ? –

+0

目前我只是在我的listview中設置directlty圖像。但我想將它保存在我的一個對象中。 (作爲位圖) – deveLost

回答

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

+0

thx的傢伙:)它的工作! – deveLost

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); 
相關問題