2016-04-03 7 views
0

私のプロジェクトでは、(Volley + NetworkImageView)を使っていくつかの画像やテキストをダウンロードし、リストビューで表示しています。ここまでは問題ありません。NetworkImageViewからビットマップを取得する方法は?

ここで、NetworkImageViewからビットマップを取得したいと思います。次のような多くの方法を試しましたが、そのうちのどれも私のために働いていませんでした。

BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable(); 
Bitmap bitmap = drawable.getBitmap(); 
別の方法

:それは内に保存されることはありませんとして任意のヘルプは高く評価され

それらの

imageView.buildDrawingCache(); 
Bitmap bmap = imageView.getDrawingCache(); 

以外は働いていた。.. ,,

答えて

1

あなたはビットマップの参照を取得することはできませんImageView。 あなたが使用してそれを得ることができますしかし:あなたが他のあなたのデフォルトの画像や誤差画像や他の画像を設定している場合が

/** 
* Sets a Bitmap as the content of this ImageView. 
* 
* @param bm The bitmap to set 
*/ 
@android.view.RemotableViewMethod 
public void setImageBitmap(Bitmap bm) { 
    // Hacky fix to force setImageDrawable to do a full setImageDrawable 
    // instead of doing an object reference comparison 
    mDrawable = null; 
    if (mRecycleableBitmapDrawable == null) { 
     mRecycleableBitmapDrawable = new ImageViewBitmapDrawable(
       mContext.getResources(), bm); 
    } else { 
     mRecycleableBitmapDrawable.setBitmap(bm); 
    } 
    setImageDrawable(mRecycleableBitmapDrawable); 
} 

:uがこれを行うあなたがボレーでそれを設定すると

((BitmapDrawable)this.getDrawable()).getBitmap(); 

beacuseをBitmapDrawableではなくNinePatchDrawableを取得することができます。ここ

がチェックする方法です:

Drawable dd = image.getDrawable(); 
    if(BitmapDrawable.class.isAssignableFrom(dd.getClass())) { 
     //good one 
     Bitmap bb = ((BitmapDrawable)dd).getBitmap(); 
    } else { 
     //cannot get that one 
    } 
あなたの答えのためにそんなに
+0

おかげで、私はこのようなものを使用できることを意味して:。 ビットマップbtmap =((BitmapDrawable)this.getDrawable())getBitmap (); –

+0

正しいですか? –

+0

はい私は自分自身を使用していますが、型をチェックすることで型のチェックをより適切に行うことができます。 – djodjo

関連する問題