我有一些 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?有解决方法吗?
谢谢
最佳答案
使用 Bitmap.Config.ARGB_8888
而不是 b.getConfig()
作为解决方法。
关于java - 为什么 Bitmap.getConfig() 返回 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9555810/