在Android中如何使用另一个位图的像素填充空白位图?

3
我想创建一个空白位图,然后根据条件从另一个包含资源的位图中获取像素Rects来填充它。这种做法可行吗?我该如何实现?
我只想在准备好绘制时才绘制位图。
目前,我正在使用Canvas通过Rect片段来绘制位图,但在准备好之前我不需要它被绘制。
谢谢!

抱歉表达不够清晰。 - NVtool
不需要道歉,我只是想帮忙;更好的问题会得到更好的答案。 - Ishtar
1个回答

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

请再解释一下,这段代码会做什么?并且请分享一些截图以获得精确的结果。 - Zia Ur Rahman

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接