1 4 package com.openedit.archive.cumulus; 5 6 import java.awt.Graphics2D ; 7 import java.awt.Image ; 8 import java.awt.RenderingHints ; 9 import java.awt.image.BufferedImage ; 10 import java.io.File ; 11 import java.io.FileOutputStream ; 12 import java.io.IOException ; 13 14 import javax.imageio.ImageIO ; 15 16 import com.openedit.OpenEditRuntimeException; 17 import com.openedit.util.FileUtils; 18 19 public class ImageToConvert implements Runnable  20 { 21 protected int fieldWidth; 22 protected int fieldHeight; 23 protected Image fieldImage; 24 protected File fieldOutput; 25 public int getWidth() 26 { 27 return fieldWidth; 28 } 29 public void setWidth(int inWidth) 30 { 31 fieldWidth = inWidth; 32 } 33 public int getHeight() 34 { 35 return fieldHeight; 36 } 37 public void setHeight(int inHeight) 38 { 39 fieldHeight = inHeight; 40 } 41 public Image getImage() 42 { 43 return fieldImage; 44 } 45 public void setImage(Image inImage) 46 { 47 fieldImage = inImage; 48 } 49 public File getOutput() 50 { 51 return fieldOutput; 52 } 53 public void setOutput(File inOutput) 54 { 55 fieldOutput = inOutput; 56 } 57 public void run() 58 { 59 BufferedImage scaledImage = new BufferedImage ( getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB ); 60 Graphics2D scaledGraphics = scaledImage.createGraphics(); 61 scaledGraphics.setRenderingHint( RenderingHints.KEY_INTERPOLATION, 62 RenderingHints.VALUE_INTERPOLATION_BICUBIC); 63 scaledGraphics.drawImage( getImage(), 0, 0, getWidth(),getHeight(), null ); 64 FileOutputStream out = null; 65 try 66 { 67 out = new FileOutputStream (getOutput()); 69 ImageIO.write(scaledImage, "jpg", out); 70 } 71 catch (IOException ex) 72 { 73 throw new OpenEditRuntimeException(ex); 74 } 75 finally 76 { 77 FileUtils.safeClose(out); 78 } 79 } 80 public String toString() 81 { 82 return getClass().getName() + " " + getOutput(); 83 } 84 } 85 | Popular Tags |