@SneakyThrows
public static void z转灰度(String filePath,String filePath2) {
//开始识别时间
long startTime = System.currentTimeMillis();
File file = new File(filePath);
File file2 = new File(filePath2);
BufferedImage image = ImageIO.read(file);
int width = image.getWidth();
int height = image.getHeight();
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
int rgb = image.getRGB(i, j);
Color color = new Color(rgb);
int gray = (int) (color.getRed() * 0.299 + color.getGreen() * 0.587 + color.getBlue() * 0.114);
Color color_end = new Color(gray, gray, gray);
image.setRGB(i, j, color_end.getRGB());
}
}
ImageIO.write(image, "jpg", file2);
SLog.info("耗时:" + (System.currentTimeMillis() - startTime) + "ms");
}
@SneakyThrows
public static void l留白(String filePath,String filePath2) {
//开始识别时间
long startTime = System.currentTimeMillis();
File file = new File(filePath);
File file2 = new File(filePath2);
BufferedImage image = ImageIO.read(file);
int width = image.getWidth();
int height = image.getHeight();
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
int rgb = image.getRGB(i, j);
Color color = new Color(rgb);
int gray = (int) (color.getRed() * 0.299 + color.getGreen() * 0.587 + color.getBlue() * 0.114);
Color color_end = new Color(gray, gray, gray);
if(color_end.getGreen()>100&&color_end.getGreen()<150){
image.setRGB(i, j, color_end.getRGB());
}else{
image.setRGB(i, j, Color.black.getRGB());
}
}
}
ImageIO.write(image, "jpg", file2);
SLog.info("耗时:" + (System.currentTimeMillis() - startTime) + "ms");
}
- 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.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.