Why does Bitmap.getConfig () return null?

I have an XML Layout created by ImageView and I want to copy the image that I click below LinearLayout.

I assigned a follow event to all events ImageView onClick:

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

So why does it b.getConfig()return null? Is there a workaround?

thank

+5
source share
1 answer

Use Bitmap.Config.ARGB_8888instead b.getConfig()as a workaround.

+1
source

All Articles