'JAVA'에 해당되는 글 51건
- 2009.06.24 JAI.jar 파일 사용하기 (ThumbNail 이미지) 1
2009. 6. 24. 17:13
JAI.jar 파일 사용하기 (ThumbNail 이미지)
2009. 6. 24. 17:13 in JAVA
import java.io.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.media.jai.JAI;
import javax.media.jai.RenderedOp;
public class JAITest{
public static boolean convert(String in, String out, int width, int height, String format){
String srcPath = "C:/file_upload/irs";
String tgtPath = System.getProperty("catalina.home");
System.out.println(tgtPath);
File saveFile = new File(out);
RenderedOp rOp = JAI.create("fileload", in);
BufferedImage im = rOp.getAsBufferedImage();
float cvtWidth = 0.0f;
float cvtHeight = 0.0f;
if(im.getWidth() > im.getHeight()){
cvtHeight = (float)height * ((float)im.getHeight() / (float)im.getWidth());
cvtWidth = width;
}
else if(im.getWidth() < im.getHeight()){
cvtWidth = (float)width * ((float)im.getWidth() / (float)im.getHeight());
cvtHeight = height;
}
else{
cvtWidth = width;
cvtHeight = height;
}
BufferedImage thumb = new BufferedImage((int)cvtWidth, (int)cvtHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = thumb.createGraphics();
g2.drawImage(im, 0, 0, (int)cvtWidth, (int)cvtHeight, null);
try{
return ImageIO.write(thumb, format, saveFile);
}
catch(IOException io){
System.out.println("예외 : " + io);
return false;
}
}
public static void main(String [] args){
String loadFile = "before.jpg";
String saveFile = "after.jpg";
if(JAITest.convert(loadFile, saveFile, 300, 300, "jpg")){
System.out.println("성공");
}
}
};