List of usage examples for java.awt Image SCALE_DEFAULT
int SCALE_DEFAULT
To view the source code for java.awt Image SCALE_DEFAULT.
Click Source Link
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);// www . j av a 2s . co 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);/*w ww.j a v a 2 s .c om*/ 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);// w w w . j a va2s .c o m frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:Main.java
public void setImage(ImageIcon icon) { image = icon.getImage().getScaledInstance(this.getWidth(), this.getHeight(), Image.SCALE_DEFAULT); repaint();/*from w w w. j a v a 2s . com*/ }
From source file:com.akman.excel.view.frmSelectImage.java
public void getImage() { try {/*w ww . jav a2 s .c o m*/ Connection conn = null; conn = Javaconnect.ConnecrDb(); String sql = "SELECT Image FROM ExcelData where Id = 1"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); if (rs.next()) { byte[] imagedata = rs.getBytes("Image"); format = new ImageIcon(imagedata); Rectangle rect = lblImage.getBounds(); //Scaling the image to fit in the picLabel Image scaledimage = format.getImage().getScaledInstance(rect.width, rect.height, Image.SCALE_DEFAULT); //converting the image back to image icon to make an acceptable picLabel format = new ImageIcon(scaledimage); lblImage.setIcon(format); } } catch (SQLException ex) { Logger.getLogger(frmSelectImage.class.getName()).log(Level.SEVERE, null, ex); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(pst); Connection conn = null; DbUtils.closeQuietly(conn); } }
From source file:com.biosis.biosislite.vistas.inventario.MantenimientoFactura.java
public MantenimientoFactura() { initComponents();//from w ww . j a va 2s. c om listar(); ImageIcon fot = new ImageIcon("img/no_disponible.png"); Icon icono = new ImageIcon(fot.getImage().getScaledInstance(lblFactura.getWidth(), lblFactura.getHeight(), Image.SCALE_DEFAULT)); lblFactura.setIcon(icono); FormularioUtil.activarComponente(panelDatos, false); FormularioUtil.activarComponente(panelOpciones, true); FormularioUtil.activarComponente(panelGuardar, false); }
From source file:components.ImagePreview.java
public void loadImage() { if (file == null) { thumbnail = null;/* w w w . j av a 2s. co m*/ return; } //Don't use createImageIcon (which is a wrapper for getResource) //because the image we're trying to load is probably not one //of this program's own resources. ImageIcon tmpIcon = new ImageIcon(file.getPath()); if (tmpIcon != null) { if (tmpIcon.getIconWidth() > 90) { thumbnail = new ImageIcon(tmpIcon.getImage().getScaledInstance(90, -1, Image.SCALE_DEFAULT)); } else { //no need to miniaturize thumbnail = tmpIcon; } } }
From source file:net.duckling.ddl.util.ImageUtils.java
/** * ???//from w w w . jav a 2 s .co m * @param tmpFilePath ? * @return */ public static boolean scare(String tmpFilePath) { try { BufferedImage src = ImageIO.read(new File(tmpFilePath)); // int width = src.getWidth(); int height = src.getHeight(); if (width > DEFAULT_WIDTH) { height = (DEFAULT_WIDTH * height) / width; width = DEFAULT_WIDTH; } Image image = src.getScaledInstance(width, height, Image.SCALE_DEFAULT); BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = tag.getGraphics(); g.drawImage(image, 0, 0, null); // ?? g.dispose(); File resultFile = new File(tmpFilePath); ImageIO.write(tag, "JPEG", resultFile);// ? return true; } catch (IOException e) { LOG.error(e); } return false; }
From source file:com.akman.excel.view.frmExportExcel.java
public void getImage() { Connection conn = Javaconnect.ConnecrDb(); PreparedStatement pst = null; ResultSet rs = null;// w w w . j ava 2 s . co m try { String sql = "SELECT MAX(ID), Image FROM ExcelData"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); if (rs.next()) { byte[] imagedata = rs.getBytes("Image"); format = new ImageIcon(imagedata); Rectangle rect = lblImage.getBounds(); //Scaling the image to fit in the picLabel Image scaledimage = format.getImage().getScaledInstance(rect.width, rect.height, Image.SCALE_DEFAULT); //converting the image back to image icon to make an acceptable picLabel format = new ImageIcon(scaledimage); lblImage.setIcon(format); } } catch (SQLException ex) { Logger.getLogger(frmSelectImage.class.getName()).log(Level.SEVERE, null, ex); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(pst); DbUtils.closeQuietly(conn); } }
From source file:org.zephyrsoft.util.gui.ImagePanel.java
private void calculateScaledImage() { Validate.notNull(image, "original image may not be null"); // use floats so division below won't round float imageWidth = image.getWidth(null); float imageHeight = image.getHeight(null); width = this.getWidth(); height = this.getHeight(); x = 0;/*from w w w . j a v a2 s . c om*/ y = 0; // take special care for a border which might exist Border border = getBorder(); if (border != null) { x = border.getBorderInsets(this).left; y = border.getBorderInsets(this).top; width -= x; width -= border.getBorderInsets(this).right; height -= y; height -= border.getBorderInsets(this).bottom; } if (width < imageWidth || height < imageHeight) { // decide which value should be taken to rescale the image if ((width / height) > (imageWidth / imageHeight)) { imageWidth = -1; imageHeight = height; } else { imageWidth = width; imageHeight = -1; } // prevent errors if panel is 0 wide or high if (imageWidth == 0) { imageWidth = -1; } if (imageHeight == 0) { imageHeight = -1; } scaledImage = image.getScaledInstance(Float.valueOf(imageWidth).intValue(), Float.valueOf(imageHeight).intValue(), Image.SCALE_DEFAULT); } else { scaledImage = image; } }