0

I need to figure out a way to get a bitmap cropped without creating another bitmap that is already present.

I have two bitmaps

int width = 50;
int height = 50;

//Bitmap A
bitmapA = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmapA.copyPixelsFromBuffer(buffer);

//Bitmap B
bitmapB = Bitmap.createBitmap(45, 45, Bitmap.Config.ARGB_8888);

bitmapA has an image data, while bitmapB has no image data. I need a cropped image of bitmapA starting from (5, 5) and put it into bitmapB without creating another new Bitmap.

While I can do

bitmapC = Bitmap.createBitmap(bitmapA, 5, 5, 45, 45);

this will create another Bitmap object. I need to copy the data of bitmapA into the already created bitmapB without creating another Bitmap / calling createBitmap

Can this be done by using Rect?

Any ideas? thanks.

4
  • bitmapC = .... change to bitmapB = .... Commented Jun 15, 2021 at 19:27
  • that is creating another bitmap Commented Jun 15, 2021 at 19:57
  • No. You had already bitmapB. Otherwise make it bitmapA = ... Commented Jun 15, 2021 at 20:22
  • 1
    I think you are talking about variables, I'm talking about new bitmap objects being allocated in the memory. Commented Jun 15, 2021 at 21:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.