5
Tôi có một số Chế độ xem ảnh được tạo bởi XML và tôi muốn sao chép hình ảnh tôi nhấp vào trong một LinearLayout
bên dưới.Tại sao Bitmap.getConfig() trả về null?
tôi đã gán sự kiện tiếp theo cho tất cả các sự kiện onClick
các 's ImageView
:
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);
}
Vậy tại sao b.getConfig()
lợi nhuận null? Có một cách giải quyết?
Cảm ơn
'getConfig' không có ở đó vì nó trả về tùy thuộc vào loại hình ảnh và/hoặc thiết bị nào tôi có? – zambotn