javax.media.jai API Docs
import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.media.jai.JAI; import javax.media.jai.RenderedOp; import com.sun.media.jai.codec.FileSeekableStream; import com.sun.media.jai.codec.ImageCodec; import com.sun.media.jai.codec.SeekableStream; public class TestThumb { public void createImageThumb(String loadfile, String savefile, int width, int height) throws IOException { if (getDecoderCheck(loadfile)) { File save = new File(savefile); RenderedOp op = JAI.create("fileload", loadfile); BufferedImage im = op.getAsBufferedImage(); if(im.getWidth() < width) width = im.getWidth(); if(im.getHeight() < height) height = im.getHeight(); BufferedImage thumb = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = thumb.createGraphics(); g2d.drawImage(im, 0, 0, width, height, null); ImageIO.write(thumb, "png", save); } } protected boolean getDecoderCheck(String filename) { SeekableStream ss = null; File file = null; String[] ext = null; String[] images = {"gif","jpeg","png","tiff","bmp"}; boolean check = false; try { file = new File(filename); ss = new FileSeekableStream(file); ext = ImageCodec.getDecoderNames(ss); for(int i=0; i-1) { check = true; break; } } } }catch(Exception e) {} return check; } }
'Application Programing > java/jsp' 카테고리의 다른 글
파라미터 관련 유틸 (0) | 2011.10.10 |
---|---|
JSTL <functions> (0) | 2011.10.10 |
Spring - ServletRequestUtils (0) | 2011.10.10 |
Recent Comments