如何使用像这样的jcolorchooser更改图像颜色
在爪哇
图1
到
图2
File input = new File("dprocessing.jpg");
image = ImageIO.read(input);
width = image.getWidth();
height = image.getHeight();
for(int i=0; i<height; i++){
for(int j=0; j<width; j++){
Color c = new Color(image.getRGB(j, i));
int red = (int)(c.getRed() * 0.299);
int green = (int)(c.getGreen() * 0.587);
int blue = (int)(c.getBlue() *0.114);
Color newColor = new Color(red+green+blue,red+green+blue,red+green+blue);
image.setRGB(j,i,newColor.getRGB());
}
}
File ouptut = new File("new_Image.jpg");
ImageIO.write(image, "jpg", ouptut);
任何帮助将不胜感激......
答案 0 :(得分:0)
您可以通过将其更改为:
来解决此问题File input = new File("dprocessing.jpg");
image = ImageIO.read(input);
width = image.getWidth();
height = image.getHeight();
for(int i=0; i<height; i++){
for(int j=0; j<width; j++){
Color c = new Color(image.getRGB(j, i));
int red = (int)(c.getRed() * 0.299);
int green = (int)(c.getGreen() * 0.587);
int blue = (int)(c.getBlue() *0.114);
if(c.getRed()>200&&c.getGreen()>200&&c.getBlue()<100){ //this is to make sure that the pixel is some form of yellow. if it is yellow, change it to purple. if it isn't keep the color the same
Color newColor = new Color(red,green,blue); //before you were making every field the sum of all 3 colors, I don't know why
image.setRGB(j,i,newColor.getRGB());
}
else{
image.setRGB(j,i,c.getRGB());
}
}
}
File ouptut = new File("new_Image.jpg");
ImageIO.write(image, "jpg", ouptut);
让我知道这是否适合您