英文:
Can I obtain a PDImageXObject for a PNG file via streams instead of BufferedImage?
问题
我希望在这里更好地了解PdfBox。我们目前使用LosslessFactory,它需要一个BufferedImage,但BufferImage完全以未压缩的方式存储在内存中。我们处理的PNG文件大小超过25MB,因此这会占用大量内存。我已经查阅了文档,但找不到适用于PNG文件且不依赖于BufferedImage的解决方案。似乎JPG可以直接使用流来避免这个问题?我是不是漏掉了什么,还是PNG文件需要BufferedImage存在的真正技术原因?
英文:
I was hoping to get a better understanding of PdfBox here. We currently use LosslessFactory which needs a BufferedImage, BufferImage however is stored wholly in memory uncompressed. We're dealing with PNG files upwards of 25mb so this ends up being very memory hungry. I've done some scanning of the doc and can't find a non BufferedImage reliant solution for PNG files. It appears JPG can use streams directly to avoid this? Am I missing something here or is there a genuine technical reason for PNG files requiring BufferedImage?
答案1
得分: 1
是的,如果您使用PDImageXObject.createFromByteArray()
,是可以实现的。这个方法使用了非公共类PNGConverter
,该类使用了PNG文件中的压缩方法。此方法从2.0.18版本开始存在,由Emmeran Seehuber在PDFBOX-4341中开发。
英文:
Yes it is possible if you use the PDImageXObject.createFromByteArray()
. That one uses the non public class PNGConverter
which uses the compression that is in PNG files. That method exists since 2.0.18 and was developed by Emmeran Seehuber in PDFBOX-4341.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论