Java Change picture size sample Share _java

Source: Internet
Author: User

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);
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.