JAI 图像调整瓶颈
我正在使用 JAI 库对一系列图像进行调整,每个图像的大小约为 1300x1000。我使用“Rescale”调整像素强度,并使用 TiledImage.createGraphics() 方法中的 Graphics2D 对象添加文本和线条。然后,我使用“subsampleaverage”调整图像大小以适合屏幕,并使用 Graphics2D.drawRenderedImage() 渲染到屏幕。到目前为止,几乎没有任何放缓,渲染大约需要 40-60 毫秒。
但是,如果我只添加文本和线条,显示速度会减慢至 100-200 毫秒。我似乎无法弄清楚这是为什么,因为在调整像素强度之后或之前添加文本就可以了。
我一直在该网站上搜索,但似乎找不到任何具体答案。许多建议都是使用 BufferedImages,但从 PlanarImages 转换为 BufferedImages 似乎也存在速度减慢的问题。
I'm using the JAI library to do adjustments on a series of images, each about 1300x1000 in size. I adjust pixel intensities with "Rescale" and add text and lines with the Graphics2D object from the TiledImage.createGraphics() method. Then I resize the image to fit the screen with "subsampleaverage" and render to screen with Graphics2D.drawRenderedImage(). Up to this point, there is little slowdown, with rendering taking about 40-60 milliseconds.
However, if I only add the text and lines, the display slows down to 100-200 milliseconds. I can't seem to figure out why this is, as adding the text after or before adjust pixel intensities is fine.
I've been searching through the site, but I can't seem to find any concrete answer. Many suggestions have been to use BufferedImages, but converting from PlanarImages to BufferedImages seems to also have a slowdown issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然,Java 中文本的渲染速度仍然非常慢。每个
Font
对象的字形必须在Graphics
对象上渲染和绘制。由于对象上有大量文本,Font
对象以及所有使用的Glyphs
都会被重新创建,从而导致速度大幅下降。即使使用 JOGL,速度也会显着下降。但使用相同的
TextRenderer
对象可以通过创建单个Font
对象并在TextRenderer
处于活动状态时重复使用它来缓解这种情况。当然,这限制了您使用多个 Font 对象,因为 JOGL 尚未实现setFont
函数,需要您为每个新字体、font 创建一个新的TextRenderer
对象样式和字体粗细。希望这对遇到类似问题的人有所帮助。
Apparently text is still rendered very slowly in Java. The glyphs for each
Font
object has to be rendered and painted on theGraphics
object. With a lot of text on the object, theFont
object along with all the usedGlyphs
are recreated, causing a massive slowdown.Even using JOGL, there is a significant slowdown. But using the same
TextRenderer
object alleviates this by creating a singleFont
object and reusing it as long as theTextRenderer
is alive. Of course, this restricts you from using multiple Font objects, as JOGL has yet to implement asetFont
function, requiring you to create a newTextRenderer
object for each new font, font style, and font weight.Hope this helps anyone with similar issues.