我的应用程序有一张图片,我需要更改 imageview 墙壁颜色中的每一个墙壁颜色,例如客厅......就像这张图片
最佳答案
您必须获取 imageView 位图中特定点的像素 RGB 值。然后您可以从那里设置像素并考虑 alpha,然后翻转您想要更改值的像素。
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inMutable = true;
opt.inScaled = false;
Bitmap ico = BitmapFactory.decodeResource(context.getResources(), R.drawable.colored_wall_pic, opt);
int color = 15132390 & 0x00FFFFFF; //15132390 is like whiteish gray
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
int alpha = ico.getPixel(x, y) & 0xFF000000;
if (alpha != 0) {
ico.setPixel(x, y, color | alpha);
}
}
}
Bitmap icon = Bitmap.createBitmap(ico.getWidth(), ico.getHeight(), ico.getConfig());
// overlay transparent mutable Bitmap on transparent background
Canvas canvas = new Canvas(icon);
canvas.drawBitmap(ico, 0, 0, null);
关于android - 在android中为多个像素更改图像png的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29353976/