我使用setRGB()來改變圖像的像素值。java中的setRGB()
int rgb=new Color(0,0,0).getRGB();
image1.setRGB(i,j,rgb); //where i,j is the boundaries of the image
在這裏,我將所有的像素值設置爲白色。但是這種變化並沒有在圖像中得到體現。任何人都知道setRGB()
它是如何工作的?
我使用setRGB()來改變圖像的像素值。java中的setRGB()
int rgb=new Color(0,0,0).getRGB();
image1.setRGB(i,j,rgb); //where i,j is the boundaries of the image
在這裏,我將所有的像素值設置爲白色。但是這種變化並沒有在圖像中得到體現。任何人都知道setRGB()
它是如何工作的?
懷特是在RGB 255,255,255這樣:
Color myWhite = new Color(255, 255, 255); // Color white
int rgb = myWhite.getRGB();
try {
BufferedImage img = null;
try {
img = ImageIO.read(new File("bubbles.bmp"));
}
catch (IOException e) {
}
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
img.setRGB(i, j, rgb);
}
}
// retrieve image
File outputfile = new File("saved.png");
ImageIO.write(img, "png", outputfile);
}
catch (IOException e) {
}
Color col = new Color(newValue, newValue, newValue);
image1.setRGB(i, j, col.getRGB());
可能還有另外一個錯誤,或者你走了錯誤的方式。所以請發佈更多的代碼。 – reporter 2012-08-14 11:51:55
幾點.. - 顏色(0,0,0)將是黑色 - setRGB設置圖像中的單個像素,而不是整個圖像 – Jimmy 2012-08-14 11:55:36
rgb顏色圖表http://www.tayloredmktg.com/ rgb /#PA – 2012-08-14 11:56:01