Example usage for java.awt Image getScaledInstance

List of usage examples for java.awt Image getScaledInstance

Introduction

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

Prototype

public Image getScaledInstance(int width, int height, int hints) 

Source Link

Document

Creates a scaled version of this image.

Usage

From source file:Main.java

public static void main(String[] args) {
    String imageFile = "A.jpg";
    RepaintManager.currentManager(null).setDoubleBufferingEnabled(false);
    Image image = Toolkit.getDefaultToolkit().getImage(Main.class.getResource(imageFile));
    image = image.getScaledInstance(imageWidth, imageHeight, Image.SCALE_SMOOTH);
    JFrame frame = new JFrame("DragImage");
    frame.getContentPane().add(new Main(image));
    frame.setSize(300, 300);//from  www . ja  va 2s  .com
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    String imageFile = "A.jpg";
    RepaintManager.currentManager(null).setDoubleBufferingEnabled(false);
    Image image = Toolkit.getDefaultToolkit().getImage(Main.class.getResource(imageFile));
    image = image.getScaledInstance(imageWidth, imageHeight, Image.SCALE_DEFAULT);
    JFrame frame = new JFrame("DragImage");
    frame.getContentPane().add(new Main(image));
    frame.setSize(300, 300);//from   w  w w .j a v a  2 s . c o m
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    String imageFile = "A.jpg";
    RepaintManager.currentManager(null).setDoubleBufferingEnabled(false);
    Image image = Toolkit.getDefaultToolkit().getImage(Main.class.getResource(imageFile));
    image = image.getScaledInstance(imageWidth, imageHeight, Image.SCALE_FAST);
    JFrame frame = new JFrame("DragImage");
    frame.getContentPane().add(new Main(image));
    frame.setSize(300, 300);//from   w ww. j a v  a 2s  .  c om
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    String imageFile = "A.jpg";
    RepaintManager.currentManager(null).setDoubleBufferingEnabled(false);
    Image image = Toolkit.getDefaultToolkit().getImage(Main.class.getResource(imageFile));
    image = image.getScaledInstance(imageWidth, imageHeight, Image.SCALE_AREA_AVERAGING);
    JFrame frame = new JFrame("DragImage");
    frame.getContentPane().add(new Main(image));
    frame.setSize(300, 300);/*from   ww  w  .j av  a  2  s.c  o m*/
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:DragImage.java

public static void main(String[] args) {
    String imageFile = "A.jpg";
    // Turn off double buffering
    RepaintManager.currentManager(null).setDoubleBufferingEnabled(false);

    Image image = Toolkit.getDefaultToolkit().getImage(DragImage.class.getResource(imageFile));
    image = image.getScaledInstance(imageWidth, imageHeight, Image.SCALE_DEFAULT);
    JFrame frame = new JFrame("DragImage");
    frame.getContentPane().add(new DragImage(image));
    frame.setSize(300, 300);/*from   w  ww  .  j  a va 2 s . co m*/
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:ClippedDragImage.java

public static void main(String[] args) {
    String imageFile = "A.jpg";
    Image image = Toolkit.getDefaultToolkit().getImage(ClippedDragImage.class.getResource(imageFile));
    image = image.getScaledInstance(imageWidth, imageHeight, Image.SCALE_DEFAULT);
    JFrame frame = new JFrame("ClippedDragImage");
    frame.getContentPane().add(new ClippedDragImage(image));
    frame.setSize(300, 300);/*  www.j av  a 2  s.  c  o m*/
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:Main.java

/**
 * Resizes the given image using Image.SCALE_SMOOTH.
 *
 * @param image the image to be resized//w ww.j  av  a 2  s.c  om
 * @param size the size to resize the width/height by (see setWidth)
 * @param setWidth whether the size applies to the height or to the width
 * @return the resized image
 */
public static Image resizeImageBy(Image image, int size, boolean setWidth) {
    if (setWidth) {
        return image.getScaledInstance(size, -1, Image.SCALE_SMOOTH);
    } else {
        return image.getScaledInstance(-1, size, Image.SCALE_SMOOTH);
    }
}

From source file:Main.java

public static Image resizeToWidth(Image image, int w) {
    int h = image.getHeight(null) * w / image.getWidth(null);
    Image newimg = image.getScaledInstance(w, h, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way  
    return newimg;
}

From source file:Main.java

public static Image resizeToHeight(Image image, int h) {
    int w = image.getWidth(null) * h / image.getHeight(null);
    Image newimg = image.getScaledInstance(w, h, Image.SCALE_SMOOTH); // scale it the smooth way  
    return newimg;
}

From source file:ueg.watchdog.util.ImageUtils.java

/**
 * Method to resize and visualize the user selected image within the image
 * label//w  w  w.  ja  va2s  . c om
 *
 * @param imagePath Path to the image
 * @param width     expected weight
 * @param height    expected height
 * @return {@link ImageIcon}
 */
public static ImageIcon resizeImage(String imagePath, int width, int height) {
    ImageIcon ic = new ImageIcon(imagePath);
    Image img = ic.getImage();
    Image newImage = img.getScaledInstance(width, height, Image.SCALE_SMOOTH);
    return new ImageIcon(newImage);
}