How do i generate thumbnail image for use with img tag ? Java web application.

Posted by Nitesh Panchal on Stack Overflow See other posts from Stack Overflow or by Nitesh Panchal
Published on 2010-05-29T05:59:37Z Indexed on 2010/05/29 6:02 UTC
Read the original article Hit count: 137

Filed under:

Hello,

I am using the below given code, but it is not working properly. Can anybody tell me how do i generate thumbnail of the image? because i am creating a photo album and i want only thumbnail images to be downloaded at first, not the entire 400-500 kb images.

 File objFile = new File(strImageFullPath);
        File targetFile = new File(strImageFullPathWithoutExt + "_small" + strFileExtension);
        Image image  = ImageIO.read(objFile);
        final int WIDTH = 150;
        final int HEIGHT = 150;
        Image thumbnailImage = image.getScaledInstance(WIDTH, HEIGHT, Image.SCALE_DEFAULT);
        BufferedImage objThumbnailBufferedImage = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
        Graphics gfx = objThumbnailBufferedImage.getGraphics();
        gfx.drawImage(image, 0, 0, null);
        gfx.dispose();
ImageIO.write(objThumbnailBufferedImage, strFileExtension.substring(1), targetFile);

Just assume that few variables like strImageFullPath,strImageFullPathWithoutExt etc they exist.

Thanks in advance :)

© Stack Overflow or respective owner

Related posts about java