DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2006

    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);
    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?

  2. #2
    Join Date
    Dec 2005
    New Jersey
    Well.... for scaling an image there's a much easier way. The Image class has a getScaledInstance which will scale an image.

    You can do something like:
    someImage = someImage.getScaledInstance(desiredWidth, desiredHeight, Image.SCALE_SMOOTH);
    [EDIT] Sorry, I see you used that. But perhaps the SCALE_SMOOTH was what you were looking for.

Similar Threads

  1. Replies: 7
    Last Post: 07-16-2013, 11:47 PM
  2. Image Size problam
    By imosha in forum Web
    Replies: 1
    Last Post: 01-09-2006, 12:00 PM
  3. queues how to print it
    By xsouldeath in forum Java
    Replies: 0
    Last Post: 12-10-2005, 10:56 PM
  4. Replies: 5
    Last Post: 12-16-2002, 06:50 PM
  5. Script for scrolling
    By Mark in forum Web
    Replies: 3
    Last Post: 08-30-2001, 11:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.