简体   繁体   中英

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!

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM