1 7 package org.ejtools.util.export; 8 9 import java.awt.Component ; 10 import java.awt.image.BufferedImage ; 11 import java.awt.image.RenderedImage ; 12 import java.io.File ; 13 import java.io.IOException ; 14 import java.util.ResourceBundle ; 15 16 import org.apache.log4j.Logger; 17 import org.ejtools.util.FileTools; 18 import org.ejtools.util.Platform; 19 20 26 public class PNGFileTools extends FileTools 27 { 28 29 private static Logger logger = Logger.getLogger(PNGFileTools.class); 30 31 private static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.util.Resources"); 32 33 public final static SimpleFileFilter PNG_FILE_FILTER = new FileTools.SimpleFileFilter(".png", resources.getString("png.file.dialog.extension.description")); 34 35 36 37 protected PNGFileTools() { } 38 39 40 46 public static void exportAsPNG(RenderedImage image, File output) 47 { 48 if (Platform.isJavaVersionCompatible(Platform.JAVA_1_4)) 49 { 50 try 51 { 52 javax.imageio.ImageIO.write(image, "PNG", output); 54 } 55 catch (IOException ioe) 56 { 57 logger.error("Can't export image as PNG", ioe); 58 } 59 } 60 } 61 62 63 69 public static void exportAsPNG(Component component, File output) 70 { 71 if (Platform.isJavaVersionCompatible(Platform.JAVA_1_4)) 72 { 73 try 74 { 75 BufferedImage image = paintAsPNG(component); 76 javax.imageio.ImageIO.write(image, "PNG", output); 78 } 79 catch (IOException ioe) 80 { 81 logger.error("Can't export image as PNG", ioe); 82 } 83 } 84 } 85 86 87 93 public static BufferedImage paintAsPNG(Component component) 94 { 95 BufferedImage image = null; 96 97 image = new BufferedImage (component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_ARGB); 98 component.paint(image.getGraphics()); 99 100 return image; 101 } 102 } 103 | Popular Tags |