Convert large picture files to small thumbnail files in Java

Source: Internet
Author: User
Thumbnail | Transform use Java to convert large picture files into small thumbnail files, requiring the use of JDK1.4,
You can change this program code to JavaBean for use in a Web environment.
The converted small thumbnail effect is good!

Import Javax.imageio.ImageIO;
Import javax.imageio.IIOException;
Import Java.awt.image.BufferedImage;
Import Java.awt.Image;
Import Java.io.File;
Import java.awt.image.AffineTransformOp;
Import Java.awt.geom.AffineTransform;

public class Imgtest {

public static void Main (String argv[]) {
try {
File fi = new file ("C:/image2.jpg"); Large image file
File fo = new file ("C:/imgtest.jpg"); The small diagram file that will be converted
int NW = 100;
AffineTransform transform = new AffineTransform ();
BufferedImage bis = imageio.read (FI);
int w = bis.getwidth ();
int h = bis.getheight ();
Double scale = (double) w/h;
int nh = (nw*h)/w;
Double SX = (double) nw/w;
Double sy = (double) nh/h;
Transform.settoscale (Sx,sy);
System.out.println (w + "" +h);
Affinetransformop ato = new Affinetransformop (transform,null);
BufferedImage bid = new BufferedImage (NW,NH,BUFFEREDIMAGE.TYPE_3BYTE_BGR);
Ato.filter (Bis,bid);
Imageio.write (BID, "jpeg", FO);
catch (Exception e) {
E.printstacktrace ();
}
}

}


Related Article

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.