我正在为我的 Bitmap
使用方法 getPixel
和 setPixel
,但它太慢了(getPixels
也一样) )。我想处理位图的每个像素,然后创建另一个位图。如何通过 RenderScript 或使用 C++ 访问像素?我认为它们更快,但我不知道该怎么做。
这就是我使用 getPixel
/setPixel
所做的:
bitmap.getPixels(colorArray, 0, width, 0, 0, width, height);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
int g = Color.green(colorArray[y * width + x]);
int b = Color.blue(colorArray[y * width + x]);
int r = Color.red(colorArray[y * width + x]);
//some color changes ....
colorArray[y * width + x] = Color.rgb(r, g, b);
returnBitmap.setPixel(x, y, colorArray[y * width + x]);
}
}
谢谢!
最佳答案
使用getPixels()
获取所有像素,修改byte[]
中的值,然后调用setPixels()
存储一次所有像素。对每个单独的像素调用 setPixel()
的开销会降低您的性能。
如果仍然不够快,您可以将数组传递给 NDK 函数。
如果您正在进行相机图像的实时处理,您可以获得 even fancier .
关于android - Android 位图中 getPixel 和 getPixel 的更快替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30559211/