Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Bitmap.getConfig() returns null?

I have some XML-Layout generated ImageView and i want to copy the image i click in a LinearLayout below.

I had assign the follow event to all the ImageView's onClick events:

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 b.getConfig() returns null? There is a workaround?

Thanks

like image 536
zambotn Avatar asked Nov 13 '22 09:11

zambotn


1 Answers

Use Bitmap.Config.ARGB_8888 instead of b.getConfig() as a workaround.

like image 103
mohit Avatar answered Nov 16 '22 02:11

mohit