1

I tried a few methods here, and basically found that I'm not I/O limited (wrote to SSD and RAMDisk with similar times). I'm aware that there are tools/techniques for JPEG and PNG, such as:

Sometimes I will be extracting images from PDFs, so my flow will look like PDFBox's ExtractImages - this writes JPEGs very quickly. However the more general

 ImageIOUtil.writeImage(image, suffix, out);

is quite slow for BufferedImages with very large dimensions.

I would actually start with a PDImage pdImage object before converting to BufferedImage (very memory usage heavy), if that makes a difference.

james.sw.clark
  • 357
  • 1
  • 8
  • 20
  • 2
    If the images in your PDF are JPEGs, you can speed up things by using the `-directJPEG` option. – Tilman Hausherr Apr 11 '19 at 05:52
  • @TilmanHausherr I set that as true by default, and it is very fast. As of TwelveMonkey's ImageIO 3.4, its JPEGImageWriter "...can now finally write CMYK JPEG files directly from CMYK BufferedImages". This may improve write speed for those images (line 400 of ExtractImages). Now I just need to see if there's a better way to save generic BufferedImages to speed up https://github.com/apache/pdfbox/blob/2d596295ae90ffc34e0c66464040a9f757dd5b0e/tools/src/main/java/org/apache/pdfbox/tools/ExtractImages.java#L425. – james.sw.clark Apr 11 '19 at 23:39
  • After seeing the code I thought about passing a BufferedOutputStream object instead of a FileOutputStream object, but then I read this: https://stackoverflow.com/questions/8712957/ – Tilman Hausherr Apr 12 '19 at 03:56

0 Answers0