生成和打印身份证时文本模糊
我正在通过 .NET 生成 ID 卡,但遇到一个问题,我插入的动态文本显得非常模糊,以至于我必须使用粗体字体才能勉强接受。
我目前正在做的事情:
- 抓取图像“框架”。
- 抓住员工的照片。
- 合并它们。
- 从生成的图像创建一个新的位图。
- 在位图顶部添加两组文本(FontBrush 颜色设置为黑色)。
- 将图像保存为
PNG
并采用我能获得的最高质量。
生成图像时是否需要采取一些措施来改善 PVC ID 卡上的打印效果?
public TextOnImage AddText(string message, Font font, PointF point)
{
using (Graphics g = Graphics.FromImage(Image))
{
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
//g.TextContrast = 0;
//g.TextRenderingHint = TextRenderingHint.AntiAlias; <-- Still didn't work
g.DrawString(message, font, Brush, point, StringFormat);
}
return this;
}
I am generating ID cards via .NET and I am having a problem where the dynamic text I insert appears so blurry that I have to use a bold font for it to be begrudgingly accepted.
What I'm currently doing:
- Grab the image "frame".
- Grab the employee's photograph.
- Merge them.
- Create a new bitmap from the generated image.
- Add two sets of text on top of the bitmap (FontBrush color set to Black).
- Save the image in
PNG
and with the highest quality I can get.
Is there something to be done when generating the image to improve the printing on PVC ID cards?
public TextOnImage AddText(string message, Font font, PointF point)
{
using (Graphics g = Graphics.FromImage(Image))
{
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
//g.TextContrast = 0;
//g.TextRenderingHint = TextRenderingHint.AntiAlias; <-- Still didn't work
g.DrawString(message, font, Brush, point, StringFormat);
}
return this;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您使用的是 GDI+,请尝试通过将图形对象上的 TextRenderingHint 设置为另一个值来关闭抗锯齿功能: http://msdn.microsoft.com/en-us/library/ssazt6bs.aspx
Assuming you are using GDI+, try turning off Anti-Aliasing by setting the TextRenderingHint on the graphics object to another value: http://msdn.microsoft.com/en-us/library/ssazt6bs.aspx
尽管这有帮助,但我最终生成了一个 PDF,以便打印机可以直接读取字体。这样,打印机就不会尝试“绘制”字体的边缘,而只是以优化的方式打印文本。
详细信息:在图像背景上叠加文本并转换为PDF
Although this helped, I ended up generating a PDF so the printer would read the font directly. This way, the printer doesn't try to "paint" the font's edges, and simply prints the text in an optimized way.
More information: Overlay text over an image background and convert to PDF