Roh*_*hit 9 java image pixel image-processing
我正在使用setRGB()来更改图像像素的值.
int rgb=new Color(0,0,0).getRGB();
image1.setRGB(i,j,rgb); //where i,j is the boundaries of the image
Run Code Online (Sandbox Code Playgroud)
在这里,我将所有像素值设置为白色.但这种变化并没有反映在图像中.任何人都知道setRGB()它是如何工作的?
小智 20
白色是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) {
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
59034 次 |
| 最近记录: |