我有(的大小1024×1024)的图像中的int数组(INT []个像素),我使用下面的循环反相一个信道...为什么我的Android应用程序如此缓慢?
int i = 0;
for (int y = 0; y < H; y++) {
for (int x = 0; x < W; x++) {
int color = pixels[i];
pixels[i] = Color.argb(Color.alpha(color), 255 - Color.red(color), Color.green(color), Color.blue(color));
i++;
}
}
这需要在我的新超过1秒Galaxy S4手机。即使在较旧的iPhone上,也可以在一瞬间运行类似的循环。有什么我在这里做错了吗?
如果用“Color.BLUE”替换“Color.argb(Color.alpha(color),255 - Color.red(color),Color.green(color),Color.blue(color))”,它变得更快。
找到解决方法。
如果我用我自己的位运算符,而不是颜色的功能,它会更快...
int i = 0;
for (int y = 0; y < H; y++) {
for (int x = 0; x < W; x++) {
int color = pixels[i];
int red = ((color & 0x00ff0000) >> 16);
pixels[i] = (color & 0xff00ffff) | ((255 - red) << 16);
//pixels[i] = Color.argb(Color.alpha(color), 255 - Color.red(color), Color.green(color), Color.blue(color));
i++;
}
}
颜色功能确实显得很慢,如果我用我自己的位运算符代替它们,它变快。 – Abix