List of usage examples for java.awt Image getScaledInstance
public Image getScaledInstance(int width, int height, int hints)
From source file:com.digitalpersona.onetouch.ui.swing.sample.Enrollment.Dashboard.java
private void list2() { List<S1_test.to_test> datas = S1_test.ret_data(""); S1_test.to_test to = (S1_test.to_test) datas.get(1); Image img = Toolkit.getDefaultToolkit().createImage(to.finger_print); ImageIcon icon = new ImageIcon(img); jLabel2.setIcon(/* w w w .j av a 2s .com*/ new ImageIcon(img.getScaledInstance(jLabel2.getWidth(), jLabel2.getHeight(), Image.SCALE_DEFAULT))); BufferedImage img1; try { InputStream input = new ByteArrayInputStream(to.finger_print); OutputStream output = new FileOutputStream("C:\\Users\\Guinness\\Documents\\10.jpg"); IOUtils.copy(input, output); } catch (IOException ex) { Logger.getLogger(Dlg_test.class.getName()).log(Level.SEVERE, null, ex); } verify(); }
From source file:nl.phanos.liteliveresultsclient.gui.ResultsWindows.java
private void showPhoto() { int pheight = jScrollPane1.getPreferredSize().height; if (jCheckBoxMenuItem2.getState() == true && this.resultFile != null && this.resultFile.Photo != null) { ImageIcon myPicture = new ImageIcon(this.resultFile.Photo); Dimension dim = getScaledDimension(myPicture.getIconWidth(), myPicture.getIconHeight(), LayerdPane.getWidth() / 2, pheight); Image image = myPicture.getImage(); // transform it Image newimg = image.getScaledInstance(dim.width, dim.height, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way myPicture = new ImageIcon(newimg); // transform it back photolabel.setIcon(myPicture);/*from w w w.ja v a2s .c o m*/ photopanel.setPreferredSize(new Dimension(LayerdPane.getWidth() / 2, pheight)); System.out.println(myPicture.getIconWidth()); } else { photopanel.setPreferredSize(new Dimension(0, pheight)); } repaint(); }
From source file:sd_mensajeria.GUI.Registro.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed final Servicios s = new Servicios(); String nombre, apellido, ciudad, user, pass; String foto;//from w w w. j av a2 s . com nombre = txtNombre.getText(); apellido = txtApellido.getText(); user = txtUsuario.getText(); pass = txtpass.getText(); ciudad = (String) jComboBox1.getSelectedItem(); foto = txtFoto.getText(); if (nombre == null && apellido == null && ciudad == null && user == null && pass == null) { JOptionPane.showMessageDialog(null, "Debe llenar todos los campos", "No ha ingresado datos", JOptionPane.ERROR_MESSAGE); } else { String semilla = "2016"; String encript = DigestUtils.sha1Hex(pass + semilla); if ("Ruta Foto".equals(foto)) { //System.out.println("Ninguna foto seleccionada.."); try { s.registrar_usuario(nombre, apellido, ciudad, user, encript, "C:\\Users\\Kattya Desiderio\\Documents\\GitHub\\SD_Mensajeria\\SD_Mensajeria\\src\\sd_conexion_bd\\avatar.jpg"); } catch (ClassNotFoundException ex) { Logger.getLogger(Registro.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(Registro.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(Registro.class.getName()).log(Level.SEVERE, null, ex); } } else { //System.out.println("Selecciono Foto..."); try { s.registrar_usuario(nombre, apellido, ciudad, user, encript, foto); } catch (IOException ex) { Logger.getLogger(Registro.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(Registro.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(Registro.class.getName()).log(Level.SEVERE, null, ex); } } File file = null; if ("Ruta Foto".equals(foto)) { file = new File( "C:\\Users\\Kattya Desiderio\\Documents\\GitHub\\SD_Mensajeria\\SD_Mensajeria\\src\\sd_conexion_bd\\avatar.jpg"); } else { file = new File(foto); } Image im = null; try { im = javax.imageio.ImageIO.read(file); } catch (IOException ex) { Logger.getLogger(Registro.class.getName()).log(Level.SEVERE, null, ex); } ImageIcon i = new ImageIcon(im.getScaledInstance(100, 120, 0)); final usuario UsuarioInfo = new usuario(); try { if (s.validar_userName(user, encript, UsuarioInfo)) { txtNombre.setText(""); txtApellido.setText(""); txtUsuario.setText(""); txtpass.setText(""); txtFoto.setText(""); this.dispose(); // this.setVisible(false); java.awt.EventQueue.invokeLater(new Runnable() { public void run() { try { Principal p = new Principal(s, null, UsuarioInfo, chatsActivos); p.setVisible(true); } catch (IOException ex) { Logger.getLogger(Registro.class.getName()).log(Level.SEVERE, null, ex); } } }); } } catch (IOException ex) { Logger.getLogger(Registro.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:org.sbs.util.ImageCompress.java
/** * gif/*ww w . j ava2 s.c o m*/ * * @param originalFile * * @param resizedFile * ? * @param newWidth * * @param newHeight * -1? * @param quality * () * @throws IOException */ public void resize(File originalFile, File resizedFile, int newWidth, int newHeight, float quality) throws IOException { if (quality < 0 || quality > 1) { throw new IllegalArgumentException("Quality has to be between 0 and 1"); } ImageIcon ii = new ImageIcon(originalFile.getCanonicalPath()); Image i = ii.getImage(); Image resizedImage = null; int iWidth = i.getWidth(null); int iHeight = i.getHeight(null); if (newHeight == -1) { if (iWidth > iHeight) { resizedImage = i.getScaledInstance(newWidth, (newWidth * iHeight) / iWidth, Image.SCALE_SMOOTH); } else { resizedImage = i.getScaledInstance((newWidth * iWidth) / iHeight, newWidth, Image.SCALE_SMOOTH); } } else { 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); // Write the jpeg to a file. FileOutputStream out = FileUtils.openOutputStream(resizedFile); // Encodes image as a JPEG data stream JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bufferedImage); param.setQuality(quality, true); encoder.setJPEGEncodeParam(param); encoder.encode(bufferedImage); }
From source file:Formulario.CapturaHuella.java
public void DibujarHuella(Image image) { lblImagenHuella.setIcon(new ImageIcon(image.getScaledInstance(lblImagenHuella.getWidth(), lblImagenHuella.getHeight(), Image.SCALE_DEFAULT))); repaint();/*from w w w . j a v a 2 s . c o m*/ }
From source file:MyFormApp.java
void pdfToimage(File filename) throws FileNotFoundException, IOException { //?pdf ? // TODO Auto-generated method stub File pdfFile = new File(filename.toString()); // pdf RandomAccessFile raf = new RandomAccessFile(pdfFile, "r"); FileChannel channel = raf.getChannel(); ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()); PDFFile pdf = new PDFFile(buf); int i = 0;// w ww .j a va 2 s .c o m String fileNameWithOutExt = FilenameUtils.removeExtension(filename.getName()); Rectangle rect = new Rectangle(0, 0, (int) pdf.getPage(i).getBBox().getWidth(), // (int) pdf.getPage(i).getBBox().getHeight()); BufferedImage bufferedImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); Image image = pdf.getPage(i).getImage(rect.width, rect.height, // width & height rect, // clip rect null, // null for the ImageObserver true, // fill background with white true // block until drawing is done ); Graphics2D bufImageGraphics = bufferedImage.createGraphics(); bufImageGraphics.drawImage(image.getScaledInstance(100, 100, Image.SCALE_AREA_AVERAGING), 0, 0, null); ImageIO.write(bufferedImage, "PNG", new File(PATH + fileNameWithOutExt + ".png")); //? }
From source file:com.codecrate.shard.ui.view.PlayerCharacterPanel.java
private ImageIcon getPortraitIcon() { Image image = character.getBio().getPortraitImage(); if (null == image) { URL portraitUrl = this.getClass().getClassLoader().getResource("images/default-portrait.jpg"); image = new ImageIcon(portraitUrl).getImage(); }/* ww w.ja va 2s. c om*/ Image scaledImage = image.getScaledInstance(150, -1, Image.SCALE_DEFAULT); return new ImageIcon(scaledImage); }
From source file:lol.search.RankedStatsPage.java
private JPanel headerPanel() { //init spacers for header for (int i = 0; i < 10; i++) { JLabel label = new JLabel("--"); label.setForeground(new Color(0, 0, 0, 0)); spacers.add(label);/*from www . j a v a 2 s. c o m*/ } //header -- to set this semi-transparent i had to remove setOpaque and replace with setBackground(...) JPanel headerPanel = new JPanel(); headerPanel.setLayout(new BorderLayout()); //headerPanel.setBorder(BorderFactory.createLineBorder(Color.WHITE)); headerPanel.setBackground(backgroundColor); headerPanel.setPreferredSize(headerDimension); //back button JPanel buttonHolder = new JPanel(); ImageIcon buttonImage = new ImageIcon("assets\\other\\button.png"); ImageIcon buttonPressedImage = new ImageIcon("assets\\other\\buttonPressed.png"); Image tempImage = buttonImage.getImage(); Image newTempImg = tempImage.getScaledInstance(75, 35, Image.SCALE_SMOOTH); buttonImage = new ImageIcon(newTempImg); JButton backButton = new JButton("BACK"); backButton.setFont(new Font("Sen-Regular", Font.CENTER_BASELINE, 10)); //custom font backButton.setForeground(Color.WHITE); //text color backButton.setBackground(new Color(0, 0, 0, 0)); backButton.setBorder(BorderFactory.createLineBorder(Color.BLACK)); backButton.setHorizontalTextPosition(AbstractButton.CENTER); backButton.setPreferredSize(new Dimension(75, 35)); //pressed button Image tempImage2 = buttonPressedImage.getImage(); Image newTempImg2 = tempImage2.getScaledInstance(75, 35, Image.SCALE_SMOOTH); buttonPressedImage = new ImageIcon(newTempImg2); backButton.setIcon(buttonImage); backButton.setRolloverIcon(buttonPressedImage); backButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //button pressed System.out.println("Going back...\n"); masterFrame.getContentPane().removeAll(); masterFrame.revalidate(); masterFrame.repaint(); MainPage MAIN_PAGE = new MainPage(masterFrame, summonerName); } }); buttonHolder.add(backButton); buttonHolder.setOpaque(false); headerPanel.add(buttonHolder, BorderLayout.LINE_START); //centerpanel JPanel centerPanel = new JPanel(); centerPanel.setLayout(new GridLayout(1, 2)); centerPanel.setOpaque(false); //centerPanel.setBorder(BorderFactory.createLineBorder(Color.WHITE)); //rightcenter JPanel rightCenter = new JPanel(); rightCenter.setOpaque(false); rightCenter.setLayout(new GridLayout(2, 1)); //top center panel JPanel topCenter = new JPanel(); topCenter.setOpaque(false); topCenter.setLayout(new BoxLayout(topCenter, BoxLayout.X_AXIS)); //profile icon JPanel proIconPanel = new JPanel(); proIconPanel.setOpaque(false); proIconPanel.setLayout(new BoxLayout(proIconPanel, BoxLayout.Y_AXIS)); JLabel profileIconLabel = new JLabel(this.profileIcon); //profileIconLabel.setBorder(BorderFactory.createLineBorder(Color.WHITE)); profileIconLabel.setAlignmentX(Component.RIGHT_ALIGNMENT); proIconPanel.add(profileIconLabel); centerPanel.add(proIconPanel); //empty spacer topCenter.add(spacers.get(0)); //summoner name JLabel summonerNameLabel = new JLabel(this.summonerName); summonerNameLabel.setFont(new Font("Sen-Regular", Font.CENTER_BASELINE, 15)); //custom font summonerNameLabel.setForeground(Color.WHITE); //text color summonerNameLabel.setAlignmentX(Component.LEFT_ALIGNMENT); topCenter.add(summonerNameLabel); //empty spacer topCenter.add(spacers.get(1)); //tier JLabel tierLabel = new JLabel(this.tier); tierLabel.setFont(new Font("Sen-Regular", Font.CENTER_BASELINE, 13)); //custom font tierLabel.setForeground(new Color(219, 219, 219)); //text color tierLabel.setAlignmentX(Component.LEFT_ALIGNMENT); topCenter.add(tierLabel); //empty spacer topCenter.add(spacers.get(2)); //division JLabel divisionLabel = new JLabel(this.division); divisionLabel.setFont(new Font("Sen-Regular", Font.CENTER_BASELINE, 13)); //custom font divisionLabel.setForeground(new Color(219, 219, 219)); //text color divisionLabel.setAlignmentX(Component.LEFT_ALIGNMENT); topCenter.add(divisionLabel); //bottom center panel JPanel bottomCenter = new JPanel(); bottomCenter.setOpaque(false); bottomCenter.setLayout(new BoxLayout(bottomCenter, BoxLayout.X_AXIS)); //empty spacer bottomCenter.add(spacers.get(3)); //season JLabel winsLabel = new JLabel(this.season); winsLabel.setFont(new Font("Sen-Regular", Font.CENTER_BASELINE, 14)); //custom font winsLabel.setForeground(new Color(219, 219, 219)); //text color winsLabel.setAlignmentX(Component.LEFT_ALIGNMENT); bottomCenter.add(winsLabel); rightCenter.add(topCenter); rightCenter.add(bottomCenter); centerPanel.add(rightCenter); headerPanel.add(centerPanel, BorderLayout.CENTER); //empty panel to balance right side JPanel ee = new JPanel(); ee.setOpaque(false); ee.setPreferredSize(new Dimension(260, 50)); headerPanel.add(ee, BorderLayout.LINE_END); return headerPanel; }
From source file:org.pentaho.reporting.libraries.base.util.ResourceBundleSupport.java
/** * Attempts to load an image from classpath. If this fails, an empty image icon is returned. * * @param resourceName the name of the image. The name should be a global resource name. * @param scale true, if the image should be scaled, false otherwise * @param large true, if the image should be scaled to 24x24, or false for 16x16 * @return the image icon./*from w w w . j a va2s .c o m*/ */ private ImageIcon createIcon(final String resourceName, final boolean scale, final boolean large) { final URL in = sourceClassLoader.getResource(resourceName); if (in == null) { logger.warn("Unable to find file in the class path: " + resourceName); return new ImageIcon(createTransparentImage(1, 1)); } final Image img = Toolkit.getDefaultToolkit().createImage(in); if (img == null) { logger.warn("Unable to instantiate the image: " + resourceName); return new ImageIcon(createTransparentImage(1, 1)); } if (scale) { if (large) { return new ImageIcon(img.getScaledInstance(24, 24, Image.SCALE_SMOOTH)); } return new ImageIcon(img.getScaledInstance(16, 16, Image.SCALE_SMOOTH)); } return new ImageIcon(img); }
From source file:it.illinois.adsc.ema.softgrid.monitoring.ui.SPMainFrame.java
private void setupGUI() throws Exception { this.getContentPane().setLayout(new GridBagLayout()); chartPanel = getChartPanel();/*from w w w . j ava 2 s. com*/ this.setPreferredSize(new Dimension(800, 700)); alertPanel.setPreferredSize(new Dimension(200, 700)); alertPanel.setMinimumSize(new Dimension(200, 700)); alertPanel.setMaximumSize(new Dimension(200, 700)); transientPanel.setPreferredSize(new Dimension(200, 700)); transientPanel.setMinimumSize(new Dimension(200, 700)); transientPanel.setMaximumSize(new Dimension(200, 700)); queryTextArea.setPreferredSize(new Dimension(300, 100)); queryTextArea.setMinimumSize(new Dimension(300, 100)); queryTextArea.setMaximumSize(new Dimension(300, 100)); monitorButton.setPreferredSize(new Dimension(30, 30)); monitorButton.setMinimumSize(new Dimension(30, 30)); monitorButton.setMaximumSize(new Dimension(30, 30)); monitorButton.setToolTipText("Execute and Monitor"); exitButton.setPreferredSize(new Dimension(30, 30)); exitButton.setMinimumSize(new Dimension(30, 30)); exitButton.setMaximumSize(new Dimension(30, 30)); exitButton.setToolTipText("Close and Exit"); clearButton.setPreferredSize(new Dimension(30, 30)); clearButton.setMinimumSize(new Dimension(30, 30)); clearButton.setMaximumSize(new Dimension(30, 30)); clearButton.setToolTipText("Reset"); runButton.setPreferredSize(new Dimension(30, 30)); runButton.setMinimumSize(new Dimension(30, 30)); runButton.setMaximumSize(new Dimension(30, 30)); runButton.setToolTipText("Initialize the server...!"); alertPanel.setLayout(new VerticalFlowLayout()); transientPanel.setLayout(new BorderLayout()); // System.out.println("new File(\"../MonitorEngine/Images/execute-xxl.png\").exists() = " + new File("../MonitorEngine/Images/execute-xxl.png").exists()); // System.out.println("execute-xxl.png = " + new File("execute-xxl.png").exists()); // System.out.println("new File().getAbsolutePath() = " + new File("openmuc.jar").getAbsolutePath()); Image img = new ImageIcon(ImageIO.read(getClass().getClassLoader().getResourceAsStream("execute-xxl.png"))) .getImage(); Image newimg = img.getScaledInstance(30, 30, java.awt.Image.SCALE_SMOOTH); ImageIcon icon = new ImageIcon(newimg); monitorButton.setIcon(icon); img = new ImageIcon(ImageIO.read(getClass().getClassLoader().getResourceAsStream("stop-xxl.png"))) .getImage(); newimg = img.getScaledInstance(30, 30, java.awt.Image.SCALE_SMOOTH); icon = new ImageIcon(newimg); exitButton.setIcon(icon); img = new ImageIcon(ImageIO.read(getClass().getClassLoader().getResourceAsStream("reset-xxl.png"))) .getImage(); newimg = img.getScaledInstance(30, 30, java.awt.Image.SCALE_SMOOTH); icon = new ImageIcon(newimg); clearButton.setIcon(icon); img = new ImageIcon(ImageIO.read(getClass().getClassLoader().getResourceAsStream("start-xxl.png"))) .getImage(); newimg = img.getScaledInstance(30, 30, java.awt.Image.SCALE_SMOOTH); icon = new ImageIcon(newimg); runButton.setIcon(icon); altertScrolPane.getViewport().add(alertPanel, null); altertScrolPane.setBorder(BorderFactory.createEtchedBorder()); logAreaScrollPane.getViewport().add(logTextArea, null); logAreaScrollPane.setBorder(BorderFactory.createEtchedBorder()); JPanel tempQueryPanel = new JPanel(); JPanel buttonPanel = new JPanel(); // tempQueryPanel.setBorder(BorderFactory.createTitledBorder("Monitor Query")); tempQueryPanel.setLayout(new GridBagLayout()); buttonPanel.setLayout(new GridBagLayout()); buttonPanel.setBorder(BorderFactory.createEtchedBorder()); buttonPanel.setOpaque(true); buttonPanel.setBackground(Color.gray); buttonPanel.add(runButton, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(6, 12, 3, 12), 0, 0)); buttonPanel.add(monitorButton, new GridBagConstraints(0, 2, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 12, 3, 12), 0, 0)); buttonPanel.add(clearButton, new GridBagConstraints(0, 3, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 12, 3, 12), 0, 0)); buttonPanel.add(exitButton, new GridBagConstraints(0, 4, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 12, 3, 12), 0, 0)); // tempQueryPanel.add(splitPane, new GridBagConstraints(0, 0, 1, 6, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); tempQueryPanel.add(buttonPanel, new GridBagConstraints(0, 0, 1, 1, 0, 1, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0)); tempQueryPanel.add(queryScrolPane, new GridBagConstraints(1, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); mainTabbedPane.add(splitPane, "Controller"); mainTabbedPane.add(ConfigPanel.getInstance(), "Configuration"); splitPane.setTopComponent(tempQueryPanel); splitPane.setDividerLocation(152); splitPane.setBottomComponent(resultTabbedPane); splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); this.getContentPane().add(mainTabbedPane, new GridBagConstraints(0, 0, 1, 2, 0.75, 0.25, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(12, 12, 12, 0), 0, 0)); // this.getContentPane().add(alertTitile, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(12, 0, 0, 12), 0, 0)); // this.getContentPane().add(altertScrolPane, new GridBagConstraints(1, 1, 1, 2, 0, 1, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 0, 12, 12), 0, 0)); // tempQueryPanel.add(queryScrolPane, new GridBagConstraints(0, 0, 1, 5, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); // this.getContentPane().add(logAreaScrollPane, new GridBagConstraints(0, 2, 1, 1, 0.75, 0.75, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(12, 12, 12, 0), 0, 0)); exitButton.addActionListener(this); monitorButton.addActionListener(this); clearButton.addActionListener(this); clearButton.setEnabled(false); clearButton.setVisible(false); monitorButton.setEnabled(true); runButton.addActionListener(this); queryTextArea.setContentType("text/html"); queryTextArea.setText("select overloadrank from virtual"); messageHandler = new MessageUIHandler(logTextArea, logAreaScrollPane); ConfigPanel.getInstance().setupConfigPanel(); }