<dependency> <groupId>com.github.jai-imageio</groupId> <artifactId>jai-imageio-core</artifactId> <version>1.4.0</version> </dependency> import java.awt.image.BufferedImage; import java.io.File; import javax.imageio.ImageIO; public class ImageProcessingExample { public static void main(String[] args) { try { BufferedImage image = ImageIO.read(new File("input.jpg")); ImageIO.write(image, "JPEG", new File("output.jpg")); } catch (Exception e) { e.printStackTrace(); } } } import java.awt.image.BufferedImage; import java.awt.Color; import java.io.File; import javax.imageio.ImageIO; public class ImageProcessingExample { public static void main(String[] args) { try { BufferedImage image = ImageIO.read(new File("input.jpg")); int width = image.getWidth(); int height = image.getHeight(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int rgb = image.getRGB(x, y); Color color = new Color(rgb); int gray = (color.getRed() + color.getGreen() + color.getBlue()) / 3; color = new Color(gray, gray, gray); image.setRGB(x, y, color.getRGB()); } } ImageIO.write(image, "JPEG", new File("output.jpg")); } catch (Exception e) { e.printStackTrace(); } } }


上一篇:
下一篇:
切换中文