Android 如何为图像的某些像素设置颜色
我在ImageView中有一个图像。我想将某些像素设置为红色。我已经取得了一些进展,但创建的图像已经失去了颜色Android 如何为图像的某些像素设置颜色,android,Android,我在ImageView中有一个图像。我想将某些像素设置为红色。我已经取得了一些进展,但创建的图像已经失去了颜色 iv.setImageBitmap(processingBitmap(bitmap)); private Bitmap processingBitmap(Bitmap src){ Bitmap dest = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());
iv.setImageBitmap(processingBitmap(bitmap));
private Bitmap processingBitmap(Bitmap src){
Bitmap dest = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());
for(int x = 0; x < src.getWidth(); x++){
for(int y = 0; y < src.getHeight(); y++){
int pixelColor = src.getPixel(x, y);
int newPixel= Color.rgb(pixelColor, pixelColor, pixelColor);
dest.setPixel(x, y, newPixel);
}
}
for (int i=5; i<50; i++)
{
dest.setPixel(i, i, Color.rgb(255, 0, 0));
}
return dest;
}
我得到一个带红线的黑色图像
感谢您的帮助 Color.rgb()接受3个字节,分别为红色、绿色和蓝色。您正在尝试设置每个像素的颜色。
最好试试这样的
byte blue = (byte) ((pixelColor & 0xff));
byte green = (byte) (((pixelColor >> 8) & 0xff));
byte red = (byte) (((pixelColor >> 16) & 0xff));
int newPixel= Color.rgb(red , green , blue);
byte blue = (byte) ((pixelColor & 0xff));
byte green = (byte) (((pixelColor >> 8) & 0xff));
byte red = (byte) (((pixelColor >> 16) & 0xff));
int newPixel= Color.rgb(red , green , blue);