【发布时间】:2018-06-10 14:30:34
【问题描述】:
假设我有一张这样的图片(实际上,我有很多,但让我们保持简单) example picture 我想用绿色替换背景颜色(那是不是道路的颜色)。
为此,我必须遍历地图中的所有像素并替换与我要删除的颜色匹配的像素。
但如你所想,我的图片不是简单的 256x256 图片,而是稍大一些,为 1440p,性能下降明显。
如何在不遍历所有像素的情况下替换所有不需要的像素。
我正在使用 Processing 3 - Java(Android),我目前正在使用这段代码:
for (x = 0; x < img.width; x++){
for (int y = 0; y < img.height; y++) {
//Color to transparent
int index = x + img.width * y;
if (img.pixels[index] == -1382175 || img.pixels[index] == 14605278 || img.pixels[index] == 16250871) {
img.pixels[index] = color(0, 0, 0, 0);
} else {
img.pixels[index] = color(map(bright, 0, 255, 64, 192));
}
}
}
【问题讨论】:
标签: java android image iteration processing