我正在为OCR处理图像,需要更改位图中一堆像素的颜色。除了使用setPixel和getPixel之外,是否有更快的方法?目前我只是用一个for循环和一个检查输入与一堆RGB值匹配并返回true的方法来完成。非常感谢!
Bitmap img = myImage.copy(Bitmap.Config.ARGB_8888, true);;
for (int w = 0; w < img.getWidth(); w++) {
for (int h = 0; h < img.getHeight(); h++) {
int value = img.getPixel(w, h);
if (filter(value)) {
img.setPixel(w, h, Color.rgb(0, 0, 0));
} else img.setPixel(w, h, Color.rgb(255, 255, 255));
}
}