Java 为什么Bitmap.getConfig()返回null?
我有一些XML布局生成的ImageView,我想复制我在下面的Java 为什么Bitmap.getConfig()返回null?,java,android,android-emulator,Java,Android,Android Emulator,我有一些XML布局生成的ImageView,我想复制我在下面的线性布局中单击的图像 我已将以下事件分配给所有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
线性布局中单击的图像
我已将以下事件分配给所有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()
返回空值呢?有解决办法吗
谢谢使用Bitmap.Config.ARGB_8888
而不是b.getConfig()
作为解决方法 getConfig
不存在,因为它的返回取决于图像的类型和/或我拥有的设备?