我可以通过流获取 PNG 文件的 PDImageXObject,而不是使用 BufferedImage 吗?

huangapple go评论75阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年8月13日 12:46:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/63388294.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定