2012-03-04 14 views
5

私はいくつかのXMLレイアウトをImageViewで生成しました。画像をコピーするには、LinearLayoutをクリックしてください。Bitmap.getConfig()がnullを返すのはなぜですか?

私はすべてのImageViewonClickイベントにフォローイベントを割り当てていた:

public void onClick(View v) { 
    // Take layout where i want to put my copy-image 
    LinearLayout savingLayout = (LinearLayout)findViewById(R.id.linearSaved); 

    //Create a new image 
    ImageView savedImage = new ImageView(savingLayout.getContext()); 
    //Take the bitmap from the object i clicked 
    Bitmap b = ((BitmapDrawable)((ImageView)v).getDrawable()).getBitmap(); 
    //Take the config of the bitmap. IT RETURNS NULL 
    Bitmap.Config cfg= b.getConfig(); 
    //Copy the Bitmap and assign it to the new ImageView... IT CRASH (cfg == null) 
    Bitmap b2 = b.copy(cfg, true); 
    savedImage.setImageBitmap(b2); 
    savingLayout.addView(savedImage); 
} 

なぜb.getConfig()はNULLを返しますか?回避策がありますか?

おかげ

答えて

1

利用Bitmap.Config.ARGB_8888代わりの回避策としてb.getConfig()

+1

'getConfig'は戻りません。なぜなら、イメージのタイプやデバイスに依存しているからです。 – zambotn

関連する問題