如何提高 ReportLab 图像质量?
我正在建造一台标签打印机。它由一个标志和一些文字组成,并不难。我已经花了 3 天的时间尝试将原始 SVG 徽标绘制到屏幕上,但 SVG 太复杂,使用了太多渐变等。
所以我有一个高质量的位图徽标(JPG 或 PNG 格式),我将其绘制在 ReportLab 画布上。相关图像远大于 85*123px。我这样做是希望 ReportLab 能够嵌入整个内容并相应地对其进行扩展。我是这样做的:
canvas.drawImage('logo.jpg', 22+xoffset, 460, 85, 123)
问题是,我的假设是错误的。它似乎在屏幕分辨率下将其缩小到 85*123px,这意味着打印时看起来不太好。
ReportLab 是否有针对画布或文档的 DPI 命令,以便我可以保持质量正常?
I'm building a label printer. It consists of a logo and some text, not tough. I have already spent 3 days trying to get the original SVG logo to draw to screen but the SVG is too complex, using too many gradients, etc.
So I have a high quality bitmapped logo (as a JPG or PNG) and I'm drawing that on a ReportLab canvas. The image in question is much larger than 85*123px. I did this hoping ReportLab would embed the whole thing and scale it accordingly. Here's how I'm doing it:
canvas.drawImage('logo.jpg', 22+xoffset, 460, 85, 123)
The problem is, my assumption was incorrect. It seems to scale it down to 85*123px at screen resolution and that means when it's printed, it doesn't look great.
Does ReportLab have any DPI commands for canvases or documents so I can keep the quality sane?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(3)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我之前在 ReportLab 公司工作过,我可以告诉您,光栅图像在包含在 PDF 中时不会经过任何自动重采样/缩小尺寸。您使用的 85*123 尺寸不是像素,而是点 (pt),它是毫米或英寸等物理单位。
我建议使用不同质量的图像打印 PDF 以确认这一点,或者使用 PDF 查看器放大非常非常远。由于图像被重新采样两次(一次在成像软件中,然后再次对 PDF 查看器可用的像素),它在 PDF 查看器中看起来总是有点模糊。
这就是我如何计算制作光栅图像的像素大小,以便在给定的物理尺寸下很好地打印:
假设我希望图片为 2 英寸宽,每英寸有 72 个点,因此我的代码中的宽度将为 144。我知道打印的良好清晰分辨率是 300dpi(每英寸点数),因此光栅图像以 600 像素宽保存。
Having previously worked at the ReportLab company, I can tell you that raster images do not go through any automatic resampling/downscaling while being included in the PDF. The 85*123 dimensions you are using are not pixels, but points (pt) which are a physical unit like millimetres or inches.
I would suggest printing the PDF with different quality images to confirm this or otherwise zooming in very, very far using your PDF viewer. It will always look a bit fuzzy in a PDF viewer as the image is resampled twice (once in the imaging software and then again to the pixels available to the PDF viewer).
This is how I would calculate what size in pixels to make a raster image for it to print well at a given physical size:
Assume I want the picture to be 2 inches wide, there are 72 points in a inch so the width in my code would be 144. I know that a good crisp resolution to print at is 300dpi (dots per inch) so the raster image is saved at 600px wide.