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:de.romankreisel.faktotum.beans.BundesbruderBean.java
/** * @param originalPicture//from w w w . jav a 2 s. c o m * @param pictureHeight * @param pictureWidth * @return * @throws IOException */ public Byte[] resizeProfilePicture(Byte[] originalPicture, int width, int height) throws IOException { BufferedImage originalImage = this.getImageFromByteArray(originalPicture); Dimension newDimension = this.getScaledDimension( new Dimension(originalImage.getWidth(), originalImage.getHeight()), new Dimension(width, height)); Image scaledImage = originalImage.getScaledInstance(newDimension.width, newDimension.height, Image.SCALE_SMOOTH); return this.storeImageToByteArray(scaledImage); }
From source file:motor.part.MainPanel.java
public MainPanel() throws SQLException, ParseException, IOException { try {// w w w .j av a 2s.c o m initComponents(); Banner_Panel.setVisible(true); Customer_Panel.setVisible(false); Admin_Panel.setVisible(false); Deleted_Message.setVisible(false); Details_Error_panel.setVisible(false); Edit_New.setVisible(false); Bill_Panel.setVisible(false); Get_Requirements_Panel.setVisible(false); Graph_Panel.setVisible(false); Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql", "root", ""); st1 = conn.createStatement(); st1.executeQuery("USE Motor_Registry"); DateFormat format = new SimpleDateFormat("dd-mm-yyyy"); Date startingDate = format.parse("10-12-2013"); My_Store = new Store_Class("MY_STORE", "MY_STORE , A-307 ,LBS Hall OF RESIDENCE , IIT KHARAGPUR ", "Admin", "user123", startingDate); st1 = conn.createStatement(); String SQLString = "Update Inventory SET Sold_Today = " + 0 + " ; "; System.out.print(SQLString); int nnnI = st1.executeUpdate(SQLString); ImageIcon ic = new ImageIcon( ImageIO.read(new File("./src/Icons/Logo.png")).getScaledInstance(415, 165, Image.SCALE_SMOOTH)); jLabel13.setIcon(ic); jLabel16.setIcon(ic); jLabel17.setIcon(ic); jLabel18.setIcon(ic); } catch (ClassNotFoundException ex) { Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:se.trixon.almond.GraphicsHelper.java
public static Image scaleImage(Image image, Dimension dimension) { Image newImage;/* w w w.j av a2 s. c o m*/ int height = image.getHeight(null); int width = image.getWidth(null); if (width > height) { newImage = image.getScaledInstance((int) dimension.getWidth(), (int) (dimension.getWidth() * height) / width, Image.SCALE_SMOOTH); } else { newImage = image.getScaledInstance((int) (dimension.getWidth() * width) / height, (int) dimension.getWidth(), Image.SCALE_SMOOTH); } return newImage; }
From source file:gdt.jgui.tool.JIconSelector.java
/** * Create the context.//www . ja v a 2s .c o m * @param console the main console. * @param locator$ the locator string. * @return the procedure context. */ @Override public JContext instantiate(JMainConsole console, String locator$) { this.console = console; try { panel.removeAll(); Properties locator = Locator.toProperties(locator$); entihome$ = locator.getProperty(Entigrator.ENTIHOME); entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); entityLabel$ = locator.getProperty(EntityHandler.ENTITY_LABEL); requesterResponseLocator$ = locator.getProperty(JRequester.REQUESTER_RESPONSE_LOCATOR); // System.out.println("IconSelector:instantiate:locator="+locator$); Entigrator entigrator = console.getEntigrator(entihome$); String icons$ = entigrator.ent_getHome(Entigrator.ICONS); File icons = new File(icons$); File[] fa = icons.listFiles(); if (fa == null) return this; ImageIcon icon; JLabel label; Image img; for (File aFa : fa) { icon = new ImageIcon(aFa.getPath()); img = icon.getImage(); img = img.getScaledInstance(smallIcon, smallIcon, java.awt.Image.SCALE_SMOOTH); icon = new ImageIcon(img); label = new JLabel(); label.setIcon(icon); label.setName(aFa.getName()); label.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { try { JLabel label = (JLabel) me.getSource(); icon$ = label.getName(); byte[] ba = Base64.decodeBase64(requesterResponseLocator$); String responseLocator$ = new String(ba, "UTF-8"); responseLocator$ = Locator.append(responseLocator$, ICON, icon$); JConsoleHandler.execute(JIconSelector.this.console, responseLocator$); } catch (Exception ee) { LOGGER.severe(ee.toString()); } } }); panel.add(label); } } catch (Exception e) { LOGGER.severe(e.toString()); } return this; }
From source file:Data.c_Card.java
public ImageIcon getImage() { try {/* ww w .j av a2s . c o m*/ ImageIcon icon = new ImageIcon( ImageIO.read(new File(getImagePath())).getScaledInstance(WIDTH, HEIGHT, Image.SCALE_SMOOTH)); return icon; } catch (Exception ex) { try { FileUtils.copyURLToFile(new URL(WebBrowserPanel.getCardImageURL(MID)), new File(getImagePath())); return getImage(); } catch (Exception ex2) { int i = 0; } } return null; }
From source file:br.prof.salesfilho.oci.image.ImageProcessor.java
public BufferedImage resize(int newWidth, int newHeigth) { Image tmp = image.getScaledInstance(newWidth, newHeigth, Image.SCALE_SMOOTH); BufferedImage dimg = new BufferedImage(newWidth, newHeigth, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = dimg.createGraphics(); g2d.drawImage(tmp, 0, 0, null);// ww w .j a v a2 s. c om g2d.dispose(); this.image = dimg; return this.image; }
From source file:de.anycook.upload.UploadHandler.java
/** * speichert eine grosse Version des Bildes * * @param image BufferedImage/*from w w w . j a va 2 s . c om*/ * @param filename Name der zu erzeugenden Datei */ private void saveBigImage(BufferedImage image, String filename) throws IOException { int height = image.getHeight(); int width = image.getWidth(); int newWidth = bigWidth; int newHeight = new Double(((double) height / (double) width) * newWidth).intValue(); if (bigHeight > -1 && newHeight > bigHeight) { newHeight = bigHeight; newWidth = new Double(((double) width / (double) height) * newHeight).intValue(); } BufferedImage newImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB); newImage.getGraphics().drawImage(image.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH), 0, 0, null); imageSaver.save("big/", filename, newImage); }
From source file:iqq.util.ImageUtil.java
/** * //w w w . j a v a 2 s . com * * @param srcFile ? * @param destFile * @param destWidth * @param destHeight */ public static void zoom(File srcFile, File destFile, int destWidth, int destHeight) { if (type == Type.jdk) { try { BufferedImage srcBufferedImage = ImageIO.read(srcFile); int srcWidth = srcBufferedImage.getWidth(); int srcHeight = srcBufferedImage.getHeight(); int width = destWidth; int height = destHeight; if (srcHeight >= srcWidth) { width = (int) Math.round(((destHeight * 1.0 / srcHeight) * srcWidth)); } else { height = (int) Math.round(((destWidth * 1.0 / srcWidth) * srcHeight)); } BufferedImage destBufferedImage = new BufferedImage(destWidth, destHeight, BufferedImage.TYPE_INT_RGB); Graphics2D graphics2D = destBufferedImage.createGraphics(); graphics2D.setBackground(BACKGROUND_COLOR); graphics2D.clearRect(0, 0, destWidth, destHeight); graphics2D.drawImage(srcBufferedImage.getScaledInstance(width, height, Image.SCALE_SMOOTH), (destWidth / 2) - (width / 2), (destHeight / 2) - (height / 2), null); graphics2D.dispose(); FileOutputStream out = new FileOutputStream(destFile); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(destBufferedImage); param.setQuality((float) DEST_QUALITY / 100, false); encoder.setJPEGEncodeParam(param); encoder.encode(destBufferedImage); out.close(); } catch (IOException e) { e.printStackTrace(); } } else { IMOperation operation = new IMOperation(); operation.thumbnail(destWidth, destHeight); operation.gravity("center"); operation.background(toHexEncoding(BACKGROUND_COLOR)); operation.extent(destWidth, destHeight); operation.quality((double) DEST_QUALITY); operation.addImage(srcFile.getPath()); operation.addImage(destFile.getPath()); if (type == Type.graphicsMagick) { ConvertCmd convertCmd = new ConvertCmd(true); if (graphicsMagickPath != null) { convertCmd.setSearchPath(graphicsMagickPath); } try { convertCmd.run(operation); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } catch (IM4JavaException e) { e.printStackTrace(); } } else { ConvertCmd convertCmd = new ConvertCmd(false); if (imageMagickPath != null) { convertCmd.setSearchPath(imageMagickPath); } try { convertCmd.run(operation); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } catch (IM4JavaException e) { e.printStackTrace(); } } } }
From source file:net.shopxx.util.ImageUtil.java
/** * //from ww w . jav a2s .c o m * @param srcFile ? * @param destFile * @param destWidth * @param destHeight */ public static void zoom(File srcFile, File destFile, int destWidth, int destHeight) { Assert.notNull(srcFile); Assert.notNull(destFile); Assert.state(destWidth > 0); Assert.state(destHeight > 0); if (type == Type.jdk) { try { BufferedImage srcBufferedImage = ImageIO.read(srcFile); int srcWidth = srcBufferedImage.getWidth(); int srcHeight = srcBufferedImage.getHeight(); int width = destWidth; int height = destHeight; if (srcHeight >= srcWidth) { width = (int) Math.round(((destHeight * 1.0 / srcHeight) * srcWidth)); } else { height = (int) Math.round(((destWidth * 1.0 / srcWidth) * srcHeight)); } BufferedImage destBufferedImage = new BufferedImage(destWidth, destHeight, BufferedImage.TYPE_INT_RGB); Graphics2D graphics2D = destBufferedImage.createGraphics(); graphics2D.setBackground(BACKGROUND_COLOR); graphics2D.clearRect(0, 0, destWidth, destHeight); graphics2D.drawImage(srcBufferedImage.getScaledInstance(width, height, Image.SCALE_SMOOTH), (destWidth / 2) - (width / 2), (destHeight / 2) - (height / 2), null); graphics2D.dispose(); FileOutputStream out = new FileOutputStream(destFile); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(destBufferedImage); param.setQuality((float) DEST_QUALITY / 100, false); encoder.setJPEGEncodeParam(param); encoder.encode(destBufferedImage); out.close(); } catch (IOException e) { e.printStackTrace(); } } else { IMOperation operation = new IMOperation(); operation.thumbnail(destWidth, destHeight); operation.gravity("center"); operation.background(toHexEncoding(BACKGROUND_COLOR)); operation.extent(destWidth, destHeight); operation.quality((double) DEST_QUALITY); operation.addImage(srcFile.getPath()); operation.addImage(destFile.getPath()); if (type == Type.graphicsMagick) { ConvertCmd convertCmd = new ConvertCmd(true); if (graphicsMagickPath != null) { convertCmd.setSearchPath(graphicsMagickPath); } try { convertCmd.run(operation); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } catch (IM4JavaException e) { e.printStackTrace(); } } else { ConvertCmd convertCmd = new ConvertCmd(false); if (imageMagickPath != null) { convertCmd.setSearchPath(imageMagickPath); } try { convertCmd.run(operation); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } catch (IM4JavaException e) { e.printStackTrace(); } } } }
From source file:org.sbs.util.ImageCompress.java
public String compressPic() { try {// w ww .jav a2s . c o m // ? file = new File(inputDir + inputFileName); if (!file.exists()) { return ""; } Image img = ImageIO.read(file); // ?? if (img.getWidth(null) == -1) { System.out.println(" can't read,retry!" + "<BR>"); return "no"; } else { int newWidth; int newHeight; // ? if (this.proportion == true) { // ? double rate1 = ((double) img.getWidth(null)) / (double) outputWidth + 0.1; double rate2 = ((double) img.getHeight(null)) / (double) outputHeight + 0.1; // ? double rate = rate1 > rate2 ? rate1 : rate2; newWidth = (int) (((double) img.getWidth(null)) / rate); newHeight = (int) (((double) img.getHeight(null)) / rate); } else { newWidth = outputWidth; // newHeight = outputHeight; // } BufferedImage tag = new BufferedImage((int) newWidth, (int) newHeight, BufferedImage.TYPE_INT_RGB); /* * Image.SCALE_SMOOTH ? ?? */ tag.getGraphics().drawImage(img.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH), 0, 0, null); FileOutputStream out = new FileOutputStream(outputDir + outputFileName); // JPEGImageEncoder?? JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(tag); out.close(); } } catch (IOException ex) { ex.printStackTrace(); } return "ok"; }