Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I copy bitmap to another bitmap without using createBitmap() and copy() on Android?

Tags:

android

bitmap

I have two bitmaps and I create them in onCreate().

Bitmap bmp1 = BitmapFactory.decodeResource(getResources(),id);
Bitmap bmp2 = BitmapFactory.decodeResource(getResources(),id);

bmp1 and bmp2 are same. I modify bmp2 in my application. After my job is done, I click "Clear" button. I am trying to copy bmp1 (clean image) to bmp2(changed image) when I click "Clear" button. But I don't want to use createBitmap() or copy() function. Because these are create new Bitmap objects. I want to use only my two bitmaps (bmp1 and bmp2). How can I copy bmp1 to bmp2? I search google but everbody do this with createBitmap() or copy().

Thanks.

like image 340
dec Avatar asked Jun 11 '13 12:06

dec


Video Answer


1 Answers

I solved my problem

First I created bmp1,bmp2 and canvas for bmp2:

bmp1 = BitmapFactory.decodeResource(cont.getResources(), R.drawable.image);
bmp2 = bmp1.copy(bmp1.getConfig(), true);
canvasBmp2 = new Canvas( bmp2 );

When I want to copy bmp1 to bmp2:

canvasBmp2.drawBitmap(bmp1, 0, 0, null);

@Override
protected void onDraw(Canvas canvas) 
{
    canvas.drawBitmap(bmp2, 0, 0, null);
}
like image 164
dec Avatar answered Sep 20 '22 12:09

dec