[ Back | Previous | Next ]

How to read size and resize image without graphics?

Package:
java.awt.*
Product:
JDK
Release:
1.1
Related Links:
Color
Cursor
FileDialog
Font
FontMetrics
Frame
general
Image
LayoutManager
Menu
ScrollPane
Comment:
DownloadJIMI http://java.sun.com/products/jimi

/** * Insert the method's description here. * Creation date: (8/12/01 6:28:37 PM) */ void writeWithResizeMediaTracker() { try { Image inImage = new ImageIcon("input.jpg").getImage(); // int maxDim = 120; double scale = (double) maxDim / (double) inImage.getHeight(null); if (inImage.getWidth(null) > inImage.getHeight(null)) { scale = (double) maxDim / (double) inImage.getWidth(null); } // Determine size of new image. //One of them // should equal maxDim. int scaledW = (int) (scale * inImage.getWidth(null)); int scaledH = (int) (scale * inImage.getHeight(null)); // // System.out.println(">> " + inImage.getSource().getClass() + " aspect ratio = " + scaledW + " , " + scaledH); Image img = inImage.getScaledInstance(scaledW , scaledH, Image.SCALE_SMOOTH); File outputFile = new File("output.jpg"); outputFile.delete(); JimiRasterImage raster = Jimi.createRasterImage(img.getSource()); FileOutputStream fos = new FileOutputStream(outputFile); Jimi.putImage("image/jpeg", raster, fos); fos.flush(); fos.close(); } catch (Throwable t) { t.printStackTrace(); } }