Example usage for java.awt Image SCALE_SMOOTH

List of usage examples for java.awt Image SCALE_SMOOTH

Introduction

In this page you can find the example usage for java.awt Image SCALE_SMOOTH.

Prototype

int SCALE_SMOOTH

To view the source code for java.awt Image SCALE_SMOOTH.

Click Source Link

Document

Choose an image-scaling algorithm that gives higher priority to image smoothness than scaling speed.

Usage

From source file:Main.java

/**
 * Creates the image icon./*from   w  ww .j  a  v  a2 s . c om*/
 * 
 * @param path
 *            the path
 * @param width
 *            the width
 * @param height
 *            the height
 * @return the image icon
 */
public static ImageIcon createImageIcon(String path, int width, int height) {
    return new ImageIcon(new ImageIcon(path).getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH));

}

From source file:Main.java

@Override
public void invalidate() {
    super.invalidate();
    int width = getWidth();
    int height = getHeight();

    if (width > 0 && height > 0) {
        scaled = img.getScaledInstance(getWidth(), getHeight(), Image.SCALE_SMOOTH);
    }/*  ww  w.ja  va 2 s  .com*/
}

From source file:Main.java

/**
 * Resizes the icons of all the abstract buttons which are contained in
 * a container.//from  w w  w  .  j  a  va  2s  .  c  om
 * 
 * @param container a container containing abstract buttons
 * @param size the size which should be used for the icons
 */
public static void scaleAllAbstractButtonIconsOf(Container container, int size) {
    for (final Component c : container.getComponents()) {
        if (c instanceof AbstractButton) {
            final ImageIcon i = (ImageIcon) ((AbstractButton) c).getIcon();
            if (i != null) {
                i.setImage(i.getImage().getScaledInstance(size, size, Image.SCALE_SMOOTH));
            }
        }
    }
}

From source file:rega.genotype.ui.util.GenotypeLib.java

public static void scalePNG(File in, File out, double perc) throws IOException {
    Image i = ImageIO.read(in);
    Image resizedImage = null;/*  w  w w.  j a v  a2 s .  c  o m*/

    int newWidth = (int) (i.getWidth(null) * perc / 100.0);
    int newHeight = (int) (i.getHeight(null) * perc / 100.0);

    resizedImage = i.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH);

    // This code ensures that all the pixels in the image are loaded.
    Image temp = new ImageIcon(resizedImage).getImage();

    // Create the buffered image.
    BufferedImage bufferedImage = new BufferedImage(temp.getWidth(null), temp.getHeight(null),
            BufferedImage.TYPE_INT_RGB);

    // Copy image to buffered image.
    Graphics g = bufferedImage.createGraphics();

    // Clear background and paint the image.
    g.setColor(Color.white);
    g.fillRect(0, 0, temp.getWidth(null), temp.getHeight(null));
    g.drawImage(temp, 0, 0, null);
    g.dispose();

    // Soften.
    float softenFactor = 0.05f;
    float[] softenArray = { 0, softenFactor, 0, softenFactor, 1 - (softenFactor * 4), softenFactor, 0,
            softenFactor, 0 };
    Kernel kernel = new Kernel(3, 3, softenArray);
    ConvolveOp cOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
    bufferedImage = cOp.filter(bufferedImage, null);

    ImageIO.write(bufferedImage, "png", out);
}

From source file:com.spstudio.common.image.ImageUtils.java

public static BufferedImage zoom(BufferedImage sourceImage, int width, int height) {
    BufferedImage zoomImage = new BufferedImage(width, height, sourceImage.getType());
    Image image = sourceImage.getScaledInstance(width, height, Image.SCALE_SMOOTH);
    Graphics gc = zoomImage.getGraphics();
    gc.setColor(Color.WHITE);//  w  ww  .  j a va2  s  .  co m
    gc.drawImage(image, 0, 0, null);
    return zoomImage;
}

From source file:com.smash.revolance.ui.model.helper.ImageHelper.java

public static BufferedImage scaleImage(BufferedImage image, double widthPerCent, double heightPerCent) {
    int w = (int) (image.getWidth() * widthPerCent);
    int h = (int) (image.getHeight() * heightPerCent);
    int t = image.getType();

    Image scaledImage = image.getScaledInstance(w, h, Image.SCALE_SMOOTH);

    BufferedImage newImg = new BufferedImage(w, h, t);
    newImg.getGraphics().drawImage(scaledImage, 0, 0, null);

    return newImg;
}

From source file:UserInterface.AdministrativeRole.FeedBackJPanel.java

private void backgroundImage(String str) {
    try {//from ww  w.ja va2  s . co  m
        BufferedImage image1 = ImageIO.read(ManageNetworkJPanel.class.getResource(str));
        image2 = image1.getScaledInstance(1200, 800, Image.SCALE_SMOOTH);
    } catch (IOException ex) {
        Logger.getLogger(SignUpJPanel.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:vista.ArchToxHome.java

/**
 * Creates new form ArchToxHome/*from   w w w.  j a  v a  2s  .  c o  m*/
 */
public ArchToxHome() {
    initComponents();
    this.setLocationRelativeTo(null);
    this.setResizable(false);
    ImageIcon img = new ImageIcon(
            "C:\\Users\\Jonathan\\Documents\\NetBeansProjects\\ArchTox\\src\\imagenes\\archtox.png");
    Icon icono = new ImageIcon(
            img.getImage().getScaledInstance(LabelLogo.getWidth(), LabelLogo.getHeight(), Image.SCALE_SMOOTH));
    LabelLogo.setIcon(icono);
    this.repaint();
    //        Dimension tamao = Toolkit.getDefaultToolkit().getScreenSize();
    //        this.setSize(tamao);
}

From source file:org.spoutcraft.launcher.skin.components.BackgroundImage.java

public BackgroundImage(int width, int height) {
    setVerticalAlignment(SwingConstants.CENTER);
    setHorizontalAlignment(SwingConstants.CENTER);
    setBounds(0, 0, width, height);/*ww w .java 2s  . c  o m*/

    setIcon(new ImageIcon(getBackgroundImage().getScaledInstance(width, height, Image.SCALE_SMOOTH)));
    setVerticalAlignment(SwingConstants.TOP);
    setHorizontalAlignment(SwingConstants.LEFT);
}

From source file:org.stanwood.nwn2.gui.view.UIIconView.java

@Override
public void paintUIObject(Graphics g) {
    int x = getX();
    int y = getY();
    try {//from   www . ja  v a  2 s .com
        BufferedImage img = getIconManager().getIcon(icon.getImg());
        int width = getWidth();
        int height = getHeight();

        if (img.getHeight() != height && img.getWidth() != width) {
            Image newImg = img.getScaledInstance(width, height, Image.SCALE_SMOOTH);
            img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
            Graphics ig = img.getGraphics();
            ig.drawImage(newImg, 0, 0, null);
        }

        if (icon.getColor() != null) {
            Color colour = getColor(icon.getColor());
            for (int w = 0; w < img.getWidth(); w++) {
                for (int h = 0; h < img.getHeight(); h++) {
                    Color rgb = ColorUtil.blend(new Color(img.getRGB(w, h)), colour);
                    img.setRGB(w, h, rgb.getRGB());
                }
            }
        }

        g.drawImage(img, x, y, null);
    } catch (Exception e) {
        log.error(e.getMessage());
        drawMissingIcon(x, y, getWidth(), getHeight(), g);
    }
}