Specify the path to the following method, the old file name, the new file name, n change multiples to complete the change picture size
Copy Code code as follows:
Package com.qq.client.tools;
Import Java.awt.Image;
Import Java.awt.image.BufferedImage;
Import Java.io.File;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import Javax.imageio.ImageIO;
Import Com.sun.image.codec.jpeg.JPEGCodec;
Import Com.sun.image.codec.jpeg.JPEGImageEncoder;
public class Jpgchange {
Path path, old file name, new file name, n change multiple
public void Changeimage (string path, String oldimg, string newimg, int n) {
try {
File File = new file (path + oldimg);
Image img = imageio.read (file);
Constructing an Image Object
int wideth = Img.getwidth (null); Get Source image width
int height = img.getheight (null); Get source Diagram length
BufferedImage tag = new BufferedImage (n * wideth, n * height,
BUFFEREDIMAGE.TYPE_INT_RGB);
Tag.getgraphics (). DrawImage (img, 0, 0, n * wideth, n * height, null);
FileOutputStream out = new FileOutputStream (path + newimg);
JPEGImageEncoder encoder = Jpegcodec.createjpegencoder (out);
Encoder.encode (tag); Near-JPEG coding
Out.close ();
catch (IOException e) {
SYSTEM.OUT.PRINTLN ("Process file exception");
E.printstacktrace ();
}
}
public static void Main (string[] args) {
Jpgchange JC = new Jpgchange ();
Jc.changeimage ("e:\\", "1.bmp", "2.bmp", 3);
}
}