-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest2.java
More file actions
26 lines (24 loc) · 874 Bytes
/
Copy pathtest2.java
File metadata and controls
26 lines (24 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package PaintCircle;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class test2 {
public static void main(String[] args) throws IOException {
BufferedImage im= ImageIO.read(new File("E:\\java-study\\Java\\source\\145620227274859.jpg"));//读取图片
int width = im.getWidth();
int height = im.getHeight();
for(int i = 0; i < width; i++){
for(int j = 0; j< height; j++){
int color=im.getRGB(i, j);
int r=(color>>16)&255;//获取red分量
im.setRGB(i,j,0);
if(r%2 == 1){
im.setRGB(i, j, 255);
}
}
}
File outputfile = new File("E:\\java-study\\Java\\source\\res.png");
ImageIO.write(im, "png",outputfile);
}
}