Upload | Upload pictures uploaded to the server, will be based on the situation will be reduced to a picture icon, we can use Java powerful graphics processing capabilities, upload the image to zoom processing.
The following program uses the latest ImageIO in jdk1.4 to read and write pictures. Use AffineTransform to zoom the picture.
/**
* @param original catalogue of Fromdir pictures
* @param todir after processing of the image storage directory
* @param imgfile Original picture
* @param sysimgfile the image filename prefix after processing
*
*/
............................
public Boolean Createthumbnail () throws Exception
{
EXT is the format of the picture GIF JPG or png
String ext= "";
Double ratio=0.0;
File F = new file (fromdir,imgfile);
if (! F.isfile ())
throw new Exception (f+ "isn't" image file error in createthumbnail!);
First of all, to determine whether the uploaded picture is gif or JPG ImageIO can only convert GIF to PNG
if (Isjpg (Imgfile)) {
ext= "JPG";
}else{
ext= "PNG";
}
File ThF = new file (todir,sysimgfile+ ".") +ext);
BufferedImage Bi = Imageio.read (F);
Let's say the picture is wide and 120 120.
Image itemp = bi.getscaledinstance (120,120,bi.scale_smooth);
if ((Bi.getheight () >120) | | (Bi.getwidth () >120)) {
if (Bi.getheight () >bi.getwidth ())
Ratio = 120.0/bi.getheight ();
Else
Ratio = 120.0/bi.getwidth ();
}
Affinetransformop op = new Affinetransformop (Affinetransform.getscaleinstance (Ratio, Ratio), NULL);
itemp = Op.filter (Bi, NULL);
The program uses the Java AWT, running Linux under the possible error, there are two ways to solve:
(1) jdk1.4 Previous version: need to install XFREE86 and XFREE86-XVFB, add export display=hostdomain:0.0
(2) After JDK 1.4 version, in the execution of the command java add parameter-djava.awt.headless=true, this is a no keyboard without the display of headless server, meaning that the server room hosting.
For server-side graphics support, there are many open source packages: Pja VNC or Acme Laboratories.
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.