为什么Bitmap.getConfig()会返回null?

5

我有一些由XML布局生成的ImageView,我希望在下面的LinearLayout中复制我点击的图像。

我将以下事件分配给所有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);
}

那么为什么b.getConfig()返回null?有解决方法吗?
谢谢。
1个回答

1

在IT相关领域中,可以使用Bitmap.Config.ARGB_8888代替b.getConfig()作为解决方法。


1
getConfig不在那里,因为它的返回取决于图像类型和/或我使用的设备是什么? - zambotn

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接