Import java. AWT. image;
Import java. AWT. image. bufferedimage;
Import java. Io. file;
Import java. Io. fileoutputstream;
Import com.sun.image.codec.jpeg. Unzip codec;
Import com.sun.image.codec.jpeg. encode imageencoder;
/**
* The engine of the synchronization tool performs all synchronization operations.
*
* @ Author Ben, <a href = "mailto" zhanghh@risesoft.net "> zhanghh@risesoft.net
*
*/
Public final class makebreviaryimage {
Public makebreviaryimage (){
}
Public static void main (string [] ARGs) throws exception {
Makebreviaryimage make = new makebreviaryimage ();
Make. createpic (new file ("D: // 111.jpg"), 220,60," d: // 222.jpg ");
}
Public void createpic (File image, int formatwideth,
Int formatheight, string savepath) throws exception {
File _ file = image; // get Image File
Image src = javax. ImageIO. ImageIO. Read (_ file); // construct image
Int imagewideth = SRC. getwidth (null); // get Wideth of Image
Int imageheight = SRC. getheight (null); // get height of Image
Int changetowideth = 0;
Int changetoheight = 0;
// Set breviary image's size
If (imagewideth> 0 & imageheight> 0 ){
// Flag = true;
If (imagewideth/imageheight> = formatwideth/formatheight ){
If (imagewideth> formatwideth ){
Changetowideth = formatwideth;
Changetoheight = (imageheight * formatwideth)/imagewideth;
} Else {
Changetowideth = imagewideth;
Changetoheight = imageheight;
}
} Else {
If (imageheight> formatheight ){
Changetoheight = formatheight;
Changetowideth = (imagewideth * formatheight)/imageheight;
} Else {
Changetowideth = imagewideth;
Changetoheight = imageheight;
}
}
}
//---------
Bufferedimage = new bufferedimage (changetowideth,
Changetoheight, bufferedimage. type_int_rgb );
Bufferedimage. getgraphics (). drawimage (SRC, 0, 0, changetowideth,
Changetoheight, null); // chage image size
Fileoutputstream out = new fileoutputstream (savepath); // out put
// Image
Required imageencoder encoder = NULL;
Encoder = export codec. createjpegencoder (out );
Encoder. encode (bufferedimage); // Like JPEG encoding
// System. Out. Print (width + "*" + height );
Out. Close ();
}
}