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

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 w  w w . ja  v a  2 s . c o  m*/
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:de.mycrobase.jcloudapp.Main.java

public static void main(String[] args) throws Exception {
    try {//from w  w w  . j av a  2s  . c o  m
        // borrowed from https://github.com/cmur2/gloudapp
        ImageNormal = ImageIO.read(Main.class.getResourceAsStream("gloudapp.png"));
        ImageWorking = ImageIO.read(Main.class.getResourceAsStream("gloudapp_working.png"));
        IconNormal = new ImageIcon(ImageNormal.getScaledInstance(64, 64, Image.SCALE_SMOOTH));
        IconLarge = new ImageIcon(ImageNormal);
    } catch (IOException ex) {
        showErrorDialog("Could not load images!\n" + ex);
        System.exit(1);
    }

    URI serviceUrl = URI.create("http://my.cl.ly:80/");
    File storage = getStorageFile();

    if (storage.exists() && storage.isFile()) {
        Yaml yaml = new Yaml();
        try {
            Map<String, String> m = (Map<String, String>) yaml.load(new FileInputStream(storage));
            // avoid NPE by implicitly assuming the presence of a service URL
            if (m.containsKey("service_url")) {
                serviceUrl = URI.create(m.get("service_url"));
            }
        } catch (IOException ex) {
            showErrorDialog("Loading settings from .cloudapp-cli failed: " + ex);
            System.exit(1);
        }
    }

    Main app = new Main(serviceUrl);
    app.login(args);
    app.run();
}

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:Main.java

/**
 * Resizes the given image using Image.SCALE_SMOOTH.
 *
 * @param image the image to be resized/*from  www . j  av a 2  s .  c o  m*/
 * @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

/**
 * If icon is an instance of {@link ImageIcon}, 
 * returns an icon scaled to the height of the component.
 * Else return the icon given.//from  w ww  .ja va2  s.co m
 */
public static Icon scaleToHeight(JComponent c, Icon icon) {

    Icon sizedIcon = icon;
    if (icon instanceof ImageIcon) {
        int h = c.getPreferredSize().height - c.getInsets().top - c.getInsets().bottom;
        sizedIcon = new ImageIcon(((ImageIcon) icon).getImage().getScaledInstance(-1, h, Image.SCALE_SMOOTH));
    }
    return sizedIcon;
}

From source file:Main.java

public static ImageIcon scaleImage(ImageIcon i, int x, int y) {
    return new ImageIcon(i.getImage().getScaledInstance(x, y, Image.SCALE_SMOOTH));
}

From source file:Main.java

/**
 * Smoothly scales the given {@link BufferedImage} to the given width and height using the
 * {@link Image#SCALE_SMOOTH} algorithm (generally bicubic resampling or bilinear filtering).
 *
 * @param source The source image.//from   w w w .j  av a 2s .c o m
 * @param width  The destination width to scale to.
 * @param height The destination height to scale to.
 * @return A new, scaled image.
 */
public static BufferedImage scaledImage(BufferedImage source, int width, int height) {
    Image scaledImage = source.getScaledInstance(width, height, Image.SCALE_SMOOTH);
    BufferedImage scaledBufImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics g = scaledBufImage.createGraphics();
    g.drawImage(scaledImage, 0, 0, null);
    g.dispose();
    return scaledBufImage;
}

From source file:com.taunova.app.libview.components.ImageHelpers.java

public static Image getScaledImage(BufferedImage image, int width) {
    Dimension d = getScaledDimension(image, width);
    Image scaledImage = image.getScaledInstance(d.width, d.height, Image.SCALE_SMOOTH);

    BufferedImage resizedImage = null;

    final boolean OPTIMIZE_SCALE = true;

    if (OPTIMIZE_SCALE) {
        ResampleOp resampleOp = new ResampleOp(100, 200);
        resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.Normal);
        resizedImage = resampleOp.filter(image, null);
    } else {//from  w  w w .  j a  v  a 2  s  .  c o  m
        resizedImage = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g = resizedImage.createGraphics();
        g.setComposite(AlphaComposite.Src);
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.drawImage(scaledImage, 0, 0, d.width, d.height, null);
        g.dispose();
    }

    return resizedImage;
}

From source file:Scale.java

public void go() {
    // Sleep first to see original
    rest();//  w w  w .  j a  v  a  2s. com
    Image original = image;
    // Down fast
    image = original.getScaledInstance(200, -1, Image.SCALE_FAST);
    repaint();
    rest();
    // Down slow
    image = original.getScaledInstance(200, -1, Image.SCALE_SMOOTH);
    repaint();
    rest();
    // Up fast
    image = original.getScaledInstance(400, -1, Image.SCALE_FAST);
    repaint();
    rest();
    // Up slow
    image = original.getScaledInstance(400, -1, Image.SCALE_SMOOTH);
    repaint();
    rest();
    System.exit(0);
}