Author: lehmi
Date: Mon Aug 20 06:11:21 2012
New Revision: 1374921

URL: http://svn.apache.org/viewvc?rev=1374921&view=rev
Log:
PDFBOX-1246: two more public methods to handle image resolution and compression 
quality

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/ImageIOUtil.java

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/ImageIOUtil.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/ImageIOUtil.java?rev=1374921&r1=1374920&r2=1374921&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/ImageIOUtil.java 
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/ImageIOUtil.java 
Mon Aug 20 06:11:21 2012
@@ -46,8 +46,14 @@ import org.w3c.dom.NodeList;
  */
 public class ImageIOUtil
 {   
-    
-    private static final int DEFAULT_SCREEN_RESOLUTION = 72;
+    /**
+     * Default screen resolution: 72dpi.
+     */
+    public static final int DEFAULT_SCREEN_RESOLUTION = 72;
+    /**
+     * Default compression quality: 1.0f.
+     */
+    public static final float DEFAULT_COMPRESSION_QUALITY = 1.0f;
     
     private ImageIOUtil()
     {
@@ -56,11 +62,13 @@ public class ImageIOUtil
 
     /**
      * Writes a buffered image to a file using the given image format.
+     * 
      * @param image the image to be written
      * @param imageFormat the target format (ex. "png")
      * @param filename used to construct the filename for the individual images
      * @param imageType the image type (see {@link BufferedImage}.TYPE_*)
      * @param resolution the resolution in dpi (dots per inch)
+     * 
      * @return true if the images were produced, false if there was an error
      * @throws IOException if an I/O error occurs
      */
@@ -75,9 +83,11 @@ public class ImageIOUtil
 
     /**
      * Writes a buffered image to a file using the given image format.
+     * 
      * @param image the image to be written
      * @param imageFormat the target format (ex. "png")
      * @param outputStream the output stream to be used for writing
+     * 
      * @return true if the images were produced, false if there was an error
      * @throws IOException if an I/O error occurs
      */
@@ -87,7 +97,37 @@ public class ImageIOUtil
         return writeImage(image, imageFormat, outputStream, 
DEFAULT_SCREEN_RESOLUTION);
     }
 
-    private static boolean writeImage(BufferedImage image, String imageFormat, 
Object outputStream, int resolution)
+    /**
+     * Writes a buffered image to a file using the given image format.
+     * 
+     * @param image the image to be written
+     * @param imageFormat the target format (ex. "png")
+     * @param outputStream the output stream to be used for writing
+     * @param resolution resolution to be used when writing the image
+     * 
+     * @return true if the images were produced, false if there was an error
+     * @throws IOException if an I/O error occurs
+     */
+    public static boolean writeImage(BufferedImage image, String imageFormat, 
Object outputStream, int resolution)
+    throws IOException
+    {
+        return writeImage(image, imageFormat, outputStream, resolution, 
DEFAULT_COMPRESSION_QUALITY);
+    }
+    
+    /**
+     * Writes a buffered image to a file using the given image format.
+     * 
+     * @param image the image to be written
+     * @param imageFormat the target format (ex. "png")
+     * @param outputStream the output stream to be used for writing
+     * @param resolution resolution to be used when writing the image
+     * @param quality quality to be used when compressing the image (0 < 
quality < 1.0f)
+     * 
+     * @return true if the images were produced, false if there was an error
+     * @throws IOException if an I/O error occurs
+     */
+    public static boolean writeImage(BufferedImage image, String imageFormat, 
Object outputStream, int resolution, 
+            float quality)
     throws IOException
     {
         boolean bSuccess = true;
@@ -113,7 +153,7 @@ public class ImageIOUtil
                         {
                             
writerParams.setCompressionType(writerParams.getCompressionTypes()[0]);
                         }
-                        writerParams.setCompressionQuality(1.0f);
+                        writerParams.setCompressionQuality(quality);
                     }
                     IIOMetadata meta = createMetadata( image, imageWriter, 
writerParams, resolution);
                     imageWriter.setOutput( output );


Reply via email to