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!
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 ();
}
}
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.