Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Populate a blank bitmap with pixels from another bitmap in Android?

I want to create a blank bitmap, which I will conditionally fill with Rects of pixels obtained from another bitmap that holds a resource. Is it possible to do that? How would I go about doing something like that?

I only want to draw the bitmap once it is ready to be drawn.

Right now I'm using Canvas to draw the bitmap using Rect segments, but I don't need it to be drawn until it is ready.

Thanks!

like image 803
NVtool Avatar asked Oct 19 '25 22:10

NVtool


1 Answers

Bitmap other = ...;
//create a blank bitmap
Bitmap newBitmap = Bitmap.createBitmap(other.getWidth(),
                      other.getHeight(), other.getConfig());

//copy some pixels from 'other'
int x=14,y=45,width=23,height=56;
int [] pixels = new int[width * height];
other.getPixels(pixels, 0, width, x, y, width, height);
newBitmap.setPixels(pixels, 0, width, x, y, width, height);
like image 125
Ishtar Avatar answered Oct 22 '25 12:10

Ishtar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!