图像上的 Java 文本
我正在 bufferedimage 中加载图像,然后在其上写入一些文本。添加文本后,它会使图像模糊且文本扭曲。我打开了文本抗锯齿功能。可以看成是附件。
I am loading an image in bufferedimage and then writing some text on it .After I add text it makes image blurry and text distorted. I have TEXT ANTIALIASING ON . It can be seen as attached.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
屏幕截图
典型输出
Screen shot
Typical outputs
您应该能够使用其他响应中显示的渲染提示来控制文本质量。我知道它有效,因为我已经做了很多次,所以我认为在这种情况下一定是其他原因导致质量下降。
如果这仍然不能帮助您找到原因,请提供更多信息(VM 版本、操作系统)和源代码。 JDK 1.6 Update 10 的文本渲染已经变得非常好,但早期版本也能够在图像中生成干净的文本,只是由于抗锯齿功能不太复杂,所以看起来不太好。
回应您的评论:
文本中的高对比度锐边是一般JPEG 压缩存在问题,因为它不是无损压缩。如果您确实需要使用 JPEG 并且无法切换到 PNG,您可以调整保存图像的压缩质量,以在图像质量和文件大小之间找到更好的折衷方案。请参阅以下代码,了解如何在保存 JPEG 时设置压缩质量。
You should be able to control the text quality with the rendering hints that are shown in the other responses. I know that it works because I have done it a lot, so I think it must be something else that causes the quality degradation in this case.
If this still doesn't help you to find the cause please provide some more information (VM version, operating system) and source code. The text rendering has become quite good with JDK 1.6 Update 10 but also earlier releases were able to produce clean text in images, it just didn't look as good because of less sophisticated antialiasing.
in response to your comment:
High contrast sharp edges as in text are a general problem with JPEG compression since it is not a lossless compression. If you really need to go with JPEG and can't switch to PNG, you can tune the compression quality of your saved image to find a better compromise between image quality and file size. See the following code on how to set the compression quality when you save a JPEG.
试试这个:
try this:
那只是java。只需关闭文本抗锯齿即可。
或者如果您确实需要它,请在单独的图像上渲染文本,如果文本是黑色,则获取颜色低于 rgb(100,100,100) 的所有像素并将它们设置为 0。然后将该缓冲区绘制到您的主图像上。
thats just java. simply turn off text anti aliasing.
or if you really need it, render the text on a separate image, if the text is black the get all pixels with color under about rgb(100,100,100) and set them to 0. then paint that buffer onto your main image.