我有一些由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?有解决方法吗?谢谢。
getConfig
不在那里,因为它的返回取决于图像类型和/或我使用的设备是什么? - zambotn