< %@ page language="java" contentType="image/jpeg" pageEncoding="UTF-8"%>
< %@page import!="java.awt.Image"%>
< %@page import!="java.awt.image.BufferedImage"%>
< %@page import!="java.io.File"%>
< %@page import!="javax.imageio.ImageIO"%>
< %@page import!="java.applet!.Applet!"%>
< %@page import!="java.awt.Button"%>
< %@page import!="java.awt.Graphics"%>
< %@page import!="java.awt.Image"%>
< %@page import!="java.awt.Rectangle"%>
< %@page import!="java.awt.TextArea"%>
< %@page import!="java.awt.event.ActionEvent"%>
< %@page import!="java.awt.event.ActionListener"%>
< %@page import!="java.awt.image.BufferedImage"%>
< %@page import!="java.awt.image.RenderedImage"%>
< %@page import!="java.io.DataInputStream"%>
< %@page import!="java.io.DataOutputStream"%>
< %@page import!="java.io.File"%>
< %@page import!="java.io.FileOutputStream"%>
< %@page import!="java.io.IOException"%>
< %@page import!="java.net.Socket"%>
< %@page import!="java.net.URL"%>
< %@page import!="javax.imageio.ImageIO"%>
< %@page import!="javax.imageio.ImageReader"%>
< %@page import!="javax.imageio.stream.ImageInputStream"%>
< %@page import!="javax.media.jai.JAI"%>
< %@page import!="javax.media.jai.ParameterBlockJAI"%>
< %@page import!="javax.media.jai.PlanarImage"%>
< %@page import!="com.sun.media.imageio.plugins.jpeg2000.J2KImageReadParam"%>
< %
String jp2Path = "C:\\Temp\\temp\\154511004210f.jp2";
String jpgPath = "C:\\Temp\\temp\\154511004210f.jpg";
BufferedImage bi = null;
try {
bi = decode(jp2Path, jpgPath, "JPEG");
} catch (Exception e) {
bi = ImageIO.read(new File("C:\\Temp\\noimage.jpg"));
}
response.setContentType("image/jpeg");
ImageIO.write(bi, "JPEG", response.getOutputStream());
%>
< %!
public static BufferedImage decode(String source, String target, String encode) throws IOException {
ImageInputStream in = ImageIO.createImageInputStream(new File(source));
ImageReader reader = ImageIO.getImageReaders(in).next();
reader.setInput(in);
boolean workaround = true;
J2KImageReadParam param = new J2KImageReadParam();
if (workaround)
param.setResolution(5);
//
param.setSourceRegion(new Rectangle(0,0,reader.getWidth(0),reader.getHeight(0)));
System.out.println("*******************************************************1");
BufferedImage image = reader.read(0, param);
System.out.println("*******************************************************2");
FileOutputStream stream = new FileOutputStream(target);
System.out.println("*******************************************************3");
JAI.create("encode", image, stream, encode, null);
stream.flush();
stream.close();
return image;
}
public static void resize(String src, String target, int width, int height) throws IOException {
BufferedImage biSrc = javax.imageio.ImageIO.read(new File(src));
if ( width < 1 && height < 1 ) {
width = biSrc.getWidth();
height = biSrc.getHeight();
} else if ( width < 1 ) {
width = (int)( (height / (float)biSrc.getHeight()) * biSrc.getWidth());
} else if ( height < 1 ) {
height = (int)( (width / (float)biSrc.getWidth()) * biSrc.getHeight()) ;
}
Image targetImage = biSrc.getScaledInstance(width, height, Image.SCALE_SMOOTH);
BufferedImage biTarget = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
biTarget.createGraphics().drawImage(targetImage, 0, 0, null);
FileOutputStream fos = new FileOutputStream(target);
ImageIO.write(biTarget, "JPEG", fos);
fos.close();
}
%>
댓글 없음:
댓글 쓰기