It puzzled me. I need to copy Bitmap from one ImageView to another. I donβt want to just copy one ImageView to another, because I need to make some changes to the bitmap along the way.
Here is the code that doesn't work.
ImageView ivSrc = (ImageView) findViewById(R.id.photo); ivSrc.setDrawingCacheEnabled(true); Bitmap bmSrc1 = ivSrc.getDrawingCache(); // will cause nullPointerException Bitmap bmSrc2 = Bitmap.createBitmap(ivSrc.getDrawingCache());//bmSrc2 will be null View vSrc = (View) ivSrc.getParent(); vSrc.setDrawingCacheEnabled(true); Bitmap bmSrc3 = Bitmap.createBitmap(vSrc.getDrawingCache()); //black bitmap
// To check bitmaps:
ImageView ivDest = (ImageView) findViewById(R.id.photo2); ivDest.setImageBitmap(bmSrc1);
I need to do it wrong, because making a copy is so simple. TIA
android imageview
Jim
source share