Search results for 'Image Resizing'. 1 post(s) found.
- 2009/06/03 How to resize image ?
Here's the simple example can resizing source image:
<%@ page import="java.io.*,
java.awt.*,
java.awt.image.*,
javax.swing.*,
com.sun.image.codec.jpeg.*"
contentType="text/html;charset=MS949" %>
<%!
public static void createthumbnail(String soruce, String target, int targetW) throws Exception
{
Image imgSource = new ImageIcon(soruce).getImage();
int oldW = imgSource.getWidth(null);
int oldH = imgSource.getHeight(null);
int newW = targetW;
int newH = (targetW * oldH) / oldW;
Image imgTarget = imgSource.getScaledInstance(newW, newH, Image.SCALE_SMOOTH);
int pixels[] = new int[newW * newH];
PixelGrabber pg = new PixelGrabber(imgTarget, 0, 0, newW, newH, pixels, 0, newW);
pg.grabPixels();
BufferedImage bi = new BufferedImage(newW, newH, BufferedImage.TYPE_INT_RGB);
bi.setRGB(0, 0, newW, newH, pixels, 0, newW);
FileOutputStream fos = new FileOutputStream(target);
JPEGImageEncoder jpeg = JPEGCodec.createJPEGEncoder(fos);
JPEGEncodeParam jep = jpeg.getDefaultJPEGEncodeParam(bi);
jep.setQuality(1, false);
jpeg.encode(bi, jep);
fos.close();
}
%>
<%
createthumbnail("c:/inetpub/c/big.jpg","c:/inetpub/c/big_result.jpg",320);
%>
Another posts included in "JSP"
| How to set and get sessions on JSP code ? (0) | 2008/10/27 |
| How to add a declaration on JSP code ? (0) | 2008/10/27 |
| How to include file in JSP ? (0) | 2008/10/27 |
| How to print out text strings on HTML directly ? (0) | 2008/10/27 |
| Put Date Time on HTML (0) | 2008/10/27 |

Prev

Rss Feed