List of usage examples for java.awt Image SCALE_SMOOTH
int SCALE_SMOOTH
To view the source code for java.awt Image SCALE_SMOOTH.
Click Source Link
From source file:AppSpringLayout.java
protected ImageIcon scaleBufferedImage(BufferedImage img, JLabel label) { ImageIcon icon = null;// w w w.j av a2 s. c om try { icon = new ImageIcon(img); double width = icon.getIconWidth(); double height = icon.getIconHeight(); double labelWidth = label.getWidth(); double labelHight = label.getHeight(); double scaleWidth = width / labelWidth; double scaleHeight = height / labelHight; if (width >= height) { // horizontal image double newWidth = width / scaleWidth; icon = new ImageIcon(icon.getImage().getScaledInstance((int) newWidth, -1, Image.SCALE_SMOOTH)); } else { // vertical image double newHeight = height / scaleHeight; icon = new ImageIcon(icon.getImage().getScaledInstance(-1, (int) newHeight, Image.SCALE_SMOOTH)); } } catch (NullPointerException e) { try { originalImage = (BufferedImage) ImageIO.read(new File("img/error.png")); } catch (IOException e2) { e2.printStackTrace(); } e.printStackTrace(); } return icon; }
From source file:org.ofbiz.product.imagemanagement.ImageManagementServices.java
public static Map<String, Object> resizeImage(BufferedImage bufImg, double imgHeight, double imgWidth, double resizeHeight, double resizeWidth) { /* VARIABLES */ BufferedImage bufNewImg;//from w ww . j a v a 2 s . c om double defaultHeight, defaultWidth, scaleFactor; Map<String, Object> result = FastMap.newInstance(); /* DIMENSIONS from ImageProperties */ defaultHeight = resizeHeight; defaultWidth = resizeWidth; /* SCALE FACTOR */ // find the right Scale Factor related to the Image Dimensions if (imgHeight > imgWidth) { scaleFactor = defaultHeight / imgHeight; // get scaleFactor from the smallest width if (defaultWidth < (imgWidth * scaleFactor)) { scaleFactor = defaultWidth / imgWidth; } } else { scaleFactor = defaultWidth / imgWidth; // get scaleFactor from the smallest height if (defaultHeight < (imgHeight * scaleFactor)) { scaleFactor = defaultHeight / imgHeight; } } int bufImgType; if (BufferedImage.TYPE_CUSTOM == bufImg.getType()) { // apply a type for image majority bufImgType = BufferedImage.TYPE_INT_ARGB_PRE; } else { bufImgType = bufImg.getType(); } // scale original image with new size Image newImg = bufImg.getScaledInstance((int) (imgWidth * scaleFactor), (int) (imgHeight * scaleFactor), Image.SCALE_SMOOTH); bufNewImg = ImageTransform.toBufferedImage(newImg, bufImgType); result.put("bufferedImage", bufNewImg); result.put("scaleFactor", scaleFactor); return result; }
From source file:org.jopac2.jbal.iso2709.Unimarc.java
@Override public void setImage(BufferedImage image, int maxx, int maxy) { if (image == null) { try {/*from w w w . j a v a 2 s .c om*/ removeTags("911"); } catch (JOpac2Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return; } ByteArrayOutputStream a = new ByteArrayOutputStream(); try { Image im = image.getScaledInstance(maxx, maxy, Image.SCALE_SMOOTH); BufferedImage dest = new BufferedImage(maxx, maxy, BufferedImage.TYPE_INT_RGB); dest.createGraphics().drawImage(im, 0, 0, null); ImageIO.write(dest, "jpeg", a); String coded = Base64.encode(a.toByteArray()); Tag t = new Tag("911", ' ', ' '); t.addField(new Field("a", coded)); try { removeTags("911"); } catch (JOpac2Exception e) { } addTag(t); a.reset(); } catch (IOException e) { e.printStackTrace(); } }
From source file:at.tuwien.ifs.somtoolbox.apps.viewer.MapPNode.java
public void setBackgroundImage(BufferedImage background) { if (backgroundImage != null) { // remove a possibly already existing background iamge removeChild(backgroundImage);/*w w w.j a v a 2s .c om*/ } originalBackgroundImage = background; backgroundImage = new PImage(background.getScaledInstance(getBackgroundImageWidth(), getBackgroundImageHeight(), Image.SCALE_SMOOTH)); backgroundImage.setPickable(false); setBackgroundImageVisibility(true); }
From source file:org.clipsmonitor.gui.MapGeneratorTopComponent.java
protected void updateLabel(String name) { try {/*from ww w. j a va 2 s . c om*/ ImageIcon icon = new ImageIcon(img.getImage(name)); Image image = icon.getImage(); // transform it Image newimg = image.getScaledInstance(90, 90, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way icon = new ImageIcon(newimg); // transform it back Icons.setIcon(icon); Icons.setToolTipText("A drawing of a " + name.toLowerCase()); Icons.setText(null); } catch (NullPointerException e) { if (!img.getMapImg().isEmpty()) { Icons.setText("Image not found"); model.error(e.getLocalizedMessage()); } } updateLogArea(); }
From source file:Form.Principal.java
public void PerfilUsuario(int idUsuario) { idUsuarioPerfil = idUsuario;/* ww w . ja v a2 s . co m*/ try { File FotoPerfil = new File("Imagenes/Fotos Perfil/" + idUsuario + ".png"); File FotoPerfil2 = new File("Imagenes/Fotos Perfil/" + idUsuario + ".jpg"); Comando = Funcion.Select(st, "SELECT * FROM usuarios WHERE id = " + idUsuario + ";"); if (FotoPerfil.exists()) { ImageIcon Imagen = new ImageIcon("Imagenes/Fotos Perfil/" + idUsuario + ".png"); Image ImagenEscalada = Imagen.getImage().getScaledInstance(jLabel2.getWidth(), jLabel2.getHeight(), Image.SCALE_SMOOTH); Icon IconoEscalado = new ImageIcon(ImagenEscalada); jLabel2.setIcon(IconoEscalado); } else if (FotoPerfil2.exists()) { ImageIcon Imagen = new ImageIcon("Imagenes/Fotos Perfil/" + idUsuario + ".jpg"); Image ImagenEscalada = Imagen.getImage().getScaledInstance(jLabel2.getWidth(), jLabel2.getHeight(), Image.SCALE_SMOOTH); Icon IconoEscalado = new ImageIcon(ImagenEscalada); jLabel2.setIcon(IconoEscalado); } else { ImageIcon Imagen = new ImageIcon(getClass().getResource("/Imagen/Default.png")); Image ImagenEscalada = Imagen.getImage().getScaledInstance(jLabel2.getWidth(), jLabel2.getHeight(), Image.SCALE_SMOOTH); Icon IconoEscalado = new ImageIcon(ImagenEscalada); jLabel2.setIcon(IconoEscalado); } while (Comando.next()) { jTextField24.setText(Comando.getString("Nombre")); jTextField26.setText(Comando.getString("contrasena")); if (Comando.getString("tipo").equals("Usuario")) { jComboBox1.setSelectedIndex(0); } else if (Comando.getString("tipo").equals("Administrador")) { jComboBox1.setSelectedIndex(1); } jTextField23.setText(Comando.getString("correo")); jPasswordField1.setText(Comando.getString("Contcorreo")); } } catch (Exception e) { System.out.println(e); } }
From source file:Form.Principal.java
public void PanelUsuarios() { int i = 0;//w ww . j ava 2 s. c o m int Altura = 0; Color gris = new Color(44, 44, 44); Color azul = new Color(0, 153, 255); Color rojo = new Color(221, 76, 76); try { //Consultamos todos los clientes ResultSet Comandos = Funcion.Select(st, "SELECT * FROM usuarios where Tipo!='Administrador';"); //Ciclo para crear un panel para cada uno while (Comandos.next()) { //Creamos un panel con alineacion a la izquierda JPanel Panel = new JPanel(); Panel.setLayout(null); jPanel12.add(Panel); //Tamao del panel Panel.setSize(500, 200); // La posicion y del panel ira incrementando para que no se encimen Altura = 40 + (i * 220); Panel.setLocation(175, Altura); Panel.setBackground(Color.white); Panel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); //Creamos label para mostrar los datos del cliente, el codigo html es para que al llegar al final del panel //se pase a la siguiente linea y para el margen izquierdo JLabel Foto = new JLabel(); Foto.setSize(150, 150); File FotoPerfil = new File("Imagenes/Fotos Perfil/" + Comandos.getInt("id") + ".png"); File FotoPerfil2 = new File("Imagenes/Fotos Perfil/" + Comandos.getInt("id") + ".jpg"); if (FotoPerfil.exists()) { ImageIcon Imagen = new ImageIcon("Imagenes/Fotos Perfil/" + Comandos.getInt("id") + ".png"); Image ImagenEscalada = Imagen.getImage().getScaledInstance(Foto.getWidth(), Foto.getHeight(), Image.SCALE_SMOOTH); Icon IconoEscalado = new ImageIcon(ImagenEscalada); Foto.setIcon(IconoEscalado); } else if (FotoPerfil2.exists()) { ImageIcon Imagen = new ImageIcon("Imagenes/Fotos Perfil/" + Comandos.getInt("id") + ".jpg"); Image ImagenEscalada = Imagen.getImage().getScaledInstance(Foto.getWidth(), Foto.getHeight(), Image.SCALE_SMOOTH); Icon IconoEscalado = new ImageIcon(ImagenEscalada); Foto.setIcon(IconoEscalado); } else { ImageIcon Imagen = new ImageIcon(getClass().getResource("/Imagen/Default.png")); Image ImagenEscalada = Imagen.getImage().getScaledInstance(Foto.getWidth(), Foto.getHeight(), Image.SCALE_SMOOTH); Icon IconoEscalado = new ImageIcon(ImagenEscalada); Foto.setIcon(IconoEscalado); } JLabel Nombre = new JLabel(); Nombre.setText("Nombre de Usuario: " + Comandos.getString("Nombre")); JLabel Contrasena = new JLabel(); Contrasena.setText(("Contrasea: " + Comandos.getString("contrasena"))); JButton Editar = new JButton(); Editar.setText("Editar"); Editar.setName(Comandos.getString("id")); Editar.setBackground(azul); JButton Eliminar = new JButton(); Eliminar.setText("Eliminar"); Eliminar.setName(Comandos.getString("id")); Eliminar.setBackground(rojo); MouseListener mlEditar = new MouseListener() { @Override public void mouseReleased(MouseEvent e) { //System.out.println("Released!"); } @Override public void mousePressed(MouseEvent e) { //System.out.println("Pressed!"); } @Override public void mouseExited(MouseEvent e) { //System.out.println("Exited!"); } @Override public void mouseEntered(MouseEvent e) { //System.out.println("Entered!"); } @Override public void mouseClicked(MouseEvent e) { presionadoactual = 24; Color azul = new Color(0, 182, 230); jButton24.setBackground(azul); JButton source = (JButton) e.getSource(); System.out.println(source.getName()); jPanel17.setVisible(false); jButton30.setLocation(470, 480); jButton31.setLocation(270, 480); jLabel2.setToolTipText(null); jTabbedPane2.setSelectedIndex(5); editando = true; PerfilUsuario(Integer.parseInt(source.getName())); Color gris = new Color(44, 44, 44); jButton4.setBackground(gris); } }; MouseListener mlEliminar = new MouseListener() { @Override public void mouseReleased(MouseEvent e) { //System.out.println("Released!"); } @Override public void mousePressed(MouseEvent e) { //System.out.println("Pressed!"); } @Override public void mouseExited(MouseEvent e) { //System.out.println("Exited!"); } @Override public void mouseEntered(MouseEvent e) { //System.out.println("Entered!"); } @Override public void mouseClicked(MouseEvent e) { JButton source = (JButton) e.getSource(); System.out.println(source.getName()); Funcion.Update(st, "DELETE FROM usuarios WHERE id = " + source.getName() + ";"); jPanel12.removeAll(); PanelUsuarios(); jPanel12.repaint(); } }; Editar.addMouseListener(mlEditar); Eliminar.addMouseListener(mlEliminar); //Fuente del texto; Nombre.setFont(new Font("Verdana", Font.PLAIN, 15)); Nombre.setForeground(gris); Contrasena.setFont(new Font("Verdana", Font.PLAIN, 15)); Contrasena.setForeground(gris); Editar.setFont(new Font("Verdana", Font.PLAIN, 15)); Editar.setForeground(Color.white); Eliminar.setFont(new Font("Verdana", Font.PLAIN, 15)); Eliminar.setForeground(Color.white); //Aadimos los label al panel correspondiente del cliente Panel.add(Foto); Panel.add(Nombre); Panel.add(Contrasena); Panel.add(Editar); Panel.add(Eliminar); Foto.setLocation(10, 20); Nombre.setLocation(170, 30); Nombre.setSize(300, 45); Contrasena.setLocation(170, 60); Contrasena.setSize(300, 45); Editar.setLocation(170, 100); Editar.setSize(120, 40); Eliminar.setLocation(315, 100); Eliminar.setSize(120, 40); i++; } } catch (SQLException ex) { Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex); } //Dependiendo de cuantos clientes se agregaron, se ajusta el tamao del panel principal para que el scroll llegue hasta ahi jPanel12.setPreferredSize(new Dimension(jPanel12.getWidth(), Altura + 150)); }
From source file:com.nikonhacker.gui.EmulatorUI.java
private static void initProgrammableTimerAnimationIcons(String buttonSize) { programmableTimersPauseButtonIcon[0] = new ImageIcon(EmulatorUI.class.getResource("images/timer.png"), "Start programmable timer"); programmableTimersPauseButtonIcon[1] = new ImageIcon(EmulatorUI.class.getResource("images/timer_pause.png"), "Start programmable timer"); if (BUTTON_SIZE_SMALL.equals(buttonSize)) { programmableTimersPauseButtonIcon[0] = new ImageIcon(programmableTimersPauseButtonIcon[0].getImage() .getScaledInstance(16, 16, java.awt.Image.SCALE_SMOOTH)); programmableTimersPauseButtonIcon[1] = new ImageIcon(programmableTimersPauseButtonIcon[1].getImage() .getScaledInstance(16, 16, java.awt.Image.SCALE_SMOOTH)); }// w w w . j ava 2 s . com }
From source file:paquete.HollywoodUI.java
public BufferedImage resize(BufferedImage img, int newW, int newH) { Image tmp = img.getScaledInstance(newW, newH, Image.SCALE_SMOOTH); BufferedImage dimg = new BufferedImage(newW, newH, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = dimg.createGraphics(); g2d.drawImage(tmp, 0, 0, null);//from ww w . j av a 2 s . co m g2d.dispose(); return dimg; }