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:examples.gp.monalisa.gui.GeneticDrawingView.java

/**
 * Scale an image to fit the size of the targetImageLabel.
 *///from   ww  w. j  ava2 s . c om
public ImageIcon scaleToImageLabel(Image image) {
    ImageIcon scaled = new ImageIcon(image);
    if (scaled.getIconHeight() > targetImageLabel.getHeight()) {
        scaled = new ImageIcon(image.getScaledInstance(-1, targetImageLabel.getHeight(), Image.SCALE_FAST));
    }
    if (scaled.getIconWidth() > targetImageLabel.getWidth()) {
        scaled = new ImageIcon(image.getScaledInstance(targetImageLabel.getWidth(), -1, Image.SCALE_FAST));
    }
    return scaled;
}

From source file:gd.gui.GeneticDrawingView.java

/**
 * Scale an image to fit the size of the targetImageLabel.
 *//*from w w  w  .  j  a v  a  2s . c om*/
public ImageIcon scaleToImageLabel(Image image) {
    ImageIcon scaled = new ImageIcon(image);

    if (scaled.getIconHeight() > targetImageLabel.getHeight()) {
        scaled = new ImageIcon(image.getScaledInstance(-1, targetImageLabel.getHeight(), Image.SCALE_FAST));
    }
    if (scaled.getIconWidth() > targetImageLabel.getWidth()) {
        scaled = new ImageIcon(image.getScaledInstance(targetImageLabel.getWidth(), -1, Image.SCALE_FAST));
    }

    return scaled;
}

From source file:org.slage.SlageImage.java

/**
 * Scale the image/*from w w w  .j ava 2 s .  com*/
 * 
 * @param anX new X size
 * @param aY new Y size
 */
public void scale(int anX, int aY) {
    this.x = anX;
    this.y = aY;

    // Scale back to its original size
    Image i;
    if (anX != 0 || aY != 0)
        i = image.getImage().getScaledInstance(xOrig, yOrig, iScaleHint);
    else
        i = image.getImage();

    // scale that to new size
    image.setImage(i.getScaledInstance(anX, aY, iScaleHint));
}

From source file:Interfaz.adminZone.java

private void ponerImagen() {

    Toolkit tk = Toolkit.getDefaultToolkit();
    String ruta = "./_data/Bicicol.png";
    Image imagen = tk.createImage(ruta);
    logo.setIcon(new ImageIcon(
            imagen.getScaledInstance(logo.getWidth(), logo.getHeight(), Image.SCALE_AREA_AVERAGING)));

}

From source file:Interfaz.adminZone.java

private void cbEmpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbEmpActionPerformed
    ArrayList<String> arr = con.search(6,
            "E.Nombre, C.Nombre Cargo, E.Telefono, COUNT(Empleado), " + "SUM(ValorTotal), E.Documento", "Venta",
            "INNER JOIN Empleado E ON E.Documento = Venta.Empleado "
                    + "INNER JOIN Cargo C ON E.Cargo = C.IdCargo " + "GROUP BY Empleado HAVING E.Nombre =" + "'"
                    + this.cbEmp.getSelectedItem().toString() + "'");
    this.txtCargo.setText(arr.get(1));
    this.txtTelefono.setText(arr.get(2));
    this.txtCan.setText(arr.get(3));
    this.txtTotal.setText(arr.get(4));

    Toolkit tk = Toolkit.getDefaultToolkit();
    String ruta = "./_data/" + arr.get(5) + ".jpg";
    Image imagen = tk.createImage(ruta);
    fotoEmp.setIcon(new ImageIcon(
            imagen.getScaledInstance(fotoEmp.getWidth(), fotoEmp.getHeight(), Image.SCALE_AREA_AVERAGING)));

}

From source file:EnrollFingerprint.Enroll.java

public void drawPicture(Image image) {
    picFingerprint.setIcon(new ImageIcon(image.getScaledInstance(picFingerprint.getWidth(),
            picFingerprint.getHeight(), Image.SCALE_DEFAULT)));
}

From source file:com.digitalpersona.onetouch.ui.swing.sample.Enrollment.Dashboard.java

public void drawPicture(Image image) {
    jLabel1.setIcon(new ImageIcon(
            image.getScaledInstance(jLabel1.getWidth(), jLabel1.getHeight(), Image.SCALE_DEFAULT)));
    fingerprint_list.add(image);//from w ww  .  j  a va  2s.c  o m
}

From source file:sd_conexion_bd.Servicios.java

/**
  * funcion para obtener los datos del contacto del usuario del chat
*//*www  .  j  a v  a  2 s.c o m*/
public boolean dato_contacto(String nombre, String apellido, usuario u) throws IOException {
    try {
        this.conectar("localhost:3306", "mensajeria", "mensajeria", "1234");
        //this.conectar("192.168.43.21:3306", "mensajeria","mensajeria","1234");
        this.consulta = this.conexion
                .prepareStatement("call obtener_info_contacto(\"" + nombre + "\",\"" + apellido + "\");");
        this.datos = this.consulta.executeQuery();
        while (this.datos.next()) {
            u.setID(datos.getInt("id"));
            u.setNombre(nombre);
            u.setApellido(apellido);
            u.setUser(datos.getString("user"));
            u.setEst_conexion(datos.getString("estado_conexion").charAt(0));
            u.setFecha_ult_conexion(datos.getTimestamp("fecha_ult_conexion"));
            Blob imagen = datos.getBlob("foto");
            if (imagen != null) {
                Image im = javax.imageio.ImageIO.read(imagen.getBinaryStream());
                ImageIcon i = new ImageIcon(im.getScaledInstance(100, 120, 0));
                u.setFoto(i);
            }
            return true;
        }
        return false;
    } catch (ClassNotFoundException | SQLException ex) {
        Logger.getLogger(Servicios.class.getName()).log(Level.SEVERE, null, ex);
        JOptionPane.showMessageDialog(null, "No se pudo conectar correctamente a la base de datos");
        System.exit(0);
    }
    return false;
}

From source file:sd_conexion_bd.Servicios.java

public boolean validar_userName(String userName, String password, usuario u) throws IOException {
    try {/*from www .  j  a v  a2s  .c om*/
        this.conectar("localhost:3306", "mensajeria", "mensajeria", "1234");
        ////this.conectar("192.168.43.21:3306", "mensajeria","mensajeria","1234");
        //System.out.println("\n" + userName+ " " + password + "\n");
        this.consulta = this.conexion
                .prepareStatement("call buscar_por_user(\"" + userName + "\",\"" + password + "\");");
        this.datos = this.consulta.executeQuery();
        while (this.datos.next()) {
            u.setID(datos.getInt("id"));
            u.setNombre(datos.getString("nombre"));
            u.setApellido(datos.getString("apellido"));
            u.setUser(userName);
            Blob imagen = datos.getBlob("foto");
            Image im = javax.imageio.ImageIO.read(imagen.getBinaryStream());
            if (im != null) {

                ImageIcon i = new ImageIcon(im.getScaledInstance(100, 120, 0));
                u.setFoto(i);

            }
            this.desconectar();
            return true;
        }
        this.desconectar();
        return false;
    } catch (ClassNotFoundException | SQLException ex) {
        Logger.getLogger(Servicios.class.getName()).log(Level.SEVERE, null, ex);
        JOptionPane.showMessageDialog(null, "--No se pudo conectar correctamente a la base de datos");
        System.exit(0);
    }
    return false;
}

From source file:z.tool.util.image.ImageUtil.java

/**
 * //from   w  ww.  j av a2s. c o m
 */
public static void resize(InputStream inputStream, ImageType destType, OutputStream outputStream,
        int maxNewWidth, int maxNewHeight) {
    if (null == inputStream) {
        throw new IllegalArgumentException("inputStream is null");
    }

    if (null == destType) {
        throw new IllegalArgumentException("destType is null");
    }

    if (null == outputStream) {
        throw new IllegalArgumentException("outputStream is null");
    }

    try {
        Image srcImage = ImageIO.read(inputStream);

        // ?
        int srcImageWidth = srcImage.getWidth(null);
        int srcImageHeight = srcImage.getHeight(null);

        if (0 == maxNewWidth || 0 == maxNewHeight
                || (srcImageWidth <= maxNewWidth && srcImageHeight <= maxNewHeight)) {
            maxNewWidth = srcImageWidth;
            maxNewHeight = srcImageHeight;
        } else {
            // 
            // ?
            if (srcImageWidth >= srcImageHeight) {
                // ???
                maxNewHeight = (int) Math.round((srcImageHeight * maxNewWidth * 1.0 / srcImageWidth));
            } else {
                // ???
                maxNewWidth = (int) Math.round((srcImageWidth * maxNewHeight * 1.0 / srcImageHeight));
            }
        }

        BufferedImage distImage = new BufferedImage(maxNewWidth, maxNewHeight, BufferedImage.TYPE_INT_ARGB_PRE);

        Graphics2D graphics2d = distImage.createGraphics();
        graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        // 
        graphics2d.drawImage(srcImage.getScaledInstance(maxNewWidth, maxNewHeight, Image.SCALE_SMOOTH), 0, 0,
                null);

        // ?
        ImageIO.write(distImage, destType.name(), outputStream);
    } catch (IOException e) {
        LOG.error("method:resize,destType:" + destType + ",maxNewHeight:" + maxNewHeight + ",maxNewWidth:"
                + maxNewWidth + ",errorMsg:" + e.getMessage(), e);
        throw new HumanNeededError(Error.IO_ERROR);
    }
}