Author: tilman
Date: Wed Mar 19 19:55:33 2014
New Revision: 1579369
URL: http://svn.apache.org/r1579369
Log:
PDFBOX-1975: deprecated one call, more javadoc
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=1579369r1=1579368r2=1579369view=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
Wed Mar 19 19:55:33 2014
@@ -46,22 +46,59 @@ public class ImageIOUtil
* Log instance
*/
private static final Log LOG = LogFactory.getLog(ImageIOUtil.class);
-
+
private ImageIOUtil()
{
}
/**
- * Writes a buffered image to a file using the given image format.
+ * Writes a buffered image to a file using the given image format. See
+ * {@link #writeImage(BufferedImage image, String formatName,
+ * OutputStream output, int dpi, float quality)} for more details.
+ *
+ * @param image the image to be written
+ * @param formatName the target format (ex. png) which is also the suffix
+ * @param filename used to construct the filename for the individual image.
+ * Its suffix will be used as the image format.
+ * @param dpi the resolution in dpi (dots per inch)
+ * @return true if the image file was produced, false if there was an
error.
+ * @throws IOException if an I/O error occurs
+ */
+public static boolean writeImage(BufferedImage image, String filename,
+int dpi) throws IOException
+{
+File file = new File(filename);
+FileOutputStream output = new FileOutputStream(file);
+try
+{
+String formatName = filename.substring(filename.lastIndexOf('.') +
1);
+return writeImage(image, formatName, output, dpi);
+}
+finally
+{
+output.close();
+}
+}
+
+/**
+ * Writes a buffered image to a file using the given image format. See
+ * {@link #writeImage(BufferedImage image, String formatName,
+ * OutputStream output, int dpi, float quality)} for more details.
+ *
* @param image the image to be written
* @param formatName the target format (ex. png) which is also the suffix
- * @param filename used to construct the filename for the individual
images, without the suffix
+ * for the filename
+ * @param filename used to construct the filename for the individual image.
+ * The formatName parameter will be used as the suffix.
* @param dpi the resolution in dpi (dots per inch)
- * @return true if the image file was produced, false if there was an error
+ * @return true if the image file was produced, false if there was an
error.
* @throws IOException if an I/O error occurs
+ * @deprecated use
+ * {@link #writeImage(BufferedImage image, String filename, int dpi)},
which
+ * uses the full filename instead of just the prefix.
*/
public static boolean writeImage(BufferedImage image, String formatName,
String filename,
- int dpi) throws IOException
+int dpi) throws IOException
{
File file = new File(filename + . + formatName);
FileOutputStream output = new FileOutputStream(file);
@@ -76,11 +113,14 @@ public class ImageIOUtil
}
/**
- * Writes a buffered image to a file using the given image format.
+ * Writes a buffered image to a file using the given image format. See
+ * {@link #writeImage(BufferedImage image, String formatName,
+ * OutputStream output, int dpi, float quality)} for more details.
+ *
* @param image the image to be written
* @param formatName the target format (ex. png)
* @param output the output stream to be used for writing
- * @return true if the image file was produced, false if there was an error
+ * @return true if the image file was produced, false if there was an
error.
* @throws IOException if an I/O error occurs
*/
public static boolean writeImage(BufferedImage image, String formatName,
OutputStream output)
@@ -90,32 +130,42 @@ public class ImageIOUtil
}
/**
- * Writes a buffered image to a file using the given image format.
+ * Writes a buffered image to a file using the given image format. See
+ * {@link #writeImage(BufferedImage image, String formatName,
+ * OutputStream output, int dpi, float quality)} for more details.
+ *
* @param image the image to be written
* @param formatName the target format (ex. png)
* @param output the output stream to be used for