ImgUtil
Introduction
This article introduces a set of methods for processing images in AWT (Abstract Window Toolkit), including scaling, cropping, converting to black and white, adding watermarks, and other operations.
Method Introduction
scale
Image Scaling
Two overloaded methods are provided: one scales the image according to the desired width and height, while the other scales the image according to a specific scale factor.
ImgUtil.scale(new File("d:/face.jpg"), new File("d:/face_result.jpg"), 0.5f);
cut
Image Cropping
ImgUtil.cut(new File("d:/face.jpg"), new File("d:/face_result.jpg"), new Rectangle(200, 200, 100, 100));
slice
Slicing an Image into Rows and Columns (Divides the image into 20 rows and 20 columns)
ImgUtil.slice(new File("e:/test2.png"), new File("e:/dest/"), 10, 10);
convert
Converts image file types, supporting GIF->JPG, GIF->PNG, PNG->JPG, PNG->GIF(X), BMP->PNG, and more
ImgUtil.convert(new File("e:/test2.png"), new File("e:/test2Convert.jpg"));
gray
Converts color image to black and white
ImgUtil.gray(new File("d:/logo.png"), new File("d:/result.png"));
pressText
Adds text watermark to an image
ImgUtil.pressText(new File("e:/pic/face.jpg"), new File("e:/pic/test2_result.png"), "版权所有", Color.WHITE, new Font("黑体", Font.BOLD, 100), 0, 0, 0.8f);
pressImage
Adds image watermark to an image
ImgUtil.pressImage(new File("d:/picTest/1.jpg"), new File("d:/picTest/dest.jpg"), ImgUtil.read(new File("d:/picTest/1432613.jpg")), 0, 0, 0.1f);
rotate
Rotates an image
BufferedImage image = ImgUtil.rotate(ImageIO.read(new File("e:/pic/366466.jpg")), 180);
ImgUtil.write(image, new File("e:/pic/result.png"));
flip
Flips an image horizontally
ImgUtil.flip(new File("d:/logo.png"), new File("d:/result.png"));