Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 23rd, 2006, 12:57 AM
Authorized User
 
Join Date: Dec 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Image size reduction

I'm storing the image in SQL database field as Image. From this image, I'm reducing its size to fit into visitors pass. But the clarity is lost. Here is the code that I' using

public static BufferedImage resizeAWT(BufferedImage src, double factorX, double factorY) {
           int w = src.getWidth();
           int h = src.getHeight();
           int newW = (int)(Math.floor(factorX * w));
           int newH = (int)(Math.floor(factorY * h));
           Image temp = src.getScaledInstance(newW, newH, Image.SCALE_AREA_AVERAGING);
           BufferedImage tgt = createBlankImage(src, newW, newH);
           Graphics2D g = tgt.createGraphics();
           g.drawImage(temp, 0, 0, null);
           g.dispose();
           return tgt;
    }

 //Uses image to create another image of the same "type", but of a factored size
    public static BufferedImage createBlankImage(BufferedImage src, int w, int h) {
        int type = src.getType();
        if (type != BufferedImage.TYPE_CUSTOM)
            return new BufferedImage(w, h, type);
        else {
            ColorModel cm = src.getColorModel();
            WritableRaster raster = src.getRaster().createCompatibleWritableRaster(w, h);
            boolean isRasterPremultiplied = src.isAlphaPremultiplied();
            return new BufferedImage(cm, raster, isRasterPremultiplied, null);
        }
    }

.....
BufferedImage image3 = resizeAWT(bi1, 0.25, 0.25);


    Is there any better method of reducing the size so that clarity is not lost?





Similar Threads
Thread Thread Starter Forum Replies Last Post
set up image size goldenstate BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 4 February 15th, 2007 07:37 PM
Image size? Olaf_l ASP.NET 1.0 and 1.1 Basics 1 May 9th, 2005 05:56 AM
Image Size kilika Classic ASP Basics 2 July 18th, 2003 01:05 PM
Image size kilika Classic ASP Professional 3 July 16th, 2003 09:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.