Java Image Scale getScaledImage(ImageIcon icon, int w, int h)

Here you can find the source of getScaledImage(ImageIcon icon, int w, int h)

Description

get Scaled Image

License

Open Source License

Declaration

public static Image getScaledImage(ImageIcon icon, int w, int h) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;

public class Main {
    public static Image getScaledImage(ImageIcon icon, int w, int h) {
        BufferedImage resizedImg = new BufferedImage(w, h,
                BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = resizedImg.createGraphics();

        g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g2.drawImage(icon.getImage(), 0, 0, w, h, null);
        g2.dispose();/*from w  w w .  ja va 2  s .c o  m*/

        return resizedImg;
    }
}

Related

  1. getScaledIcon(final Image image, final double scale)
  2. getScaledImage(final ImageIcon icon, final int newMaxWidth, final int newMaxHeight, final boolean maintainRatio)
  3. getScaledImage(Image image, int maxWidth, int maxHeight)
  4. getScaledImage(Image imagen, double scaleW, double scaleH)
  5. getScaledImage(Image srcImg, int w, int h)
  6. getScaledImage(ImageIcon srcImg, int h, int maxWidth)
  7. getScaleToFit(JPanel componentToFit, File imageFile)
  8. scaleImage(Image image, float scale)
  9. scaleImage(Image image, float widthPercentage, float heightPercentage)