【问题标题】:ReportLab Python: Transparent background is changed to black and poor image qualityReportLab Python:透明背景改为黑色,图像质量差
【发布时间】:2017-07-14 00:44:15
【问题描述】:

我在导入具有透明背景的高质量 PNG 图像时遇到问题,但是当使用 ReportLab 将图像导入 PDF 时,背景变为黑色。

关于如何防止这种情况发生的任何想法?

已解决:将掩码设置为“自动”而不是“无”。

第二期:

导入的 PNG 文件的质量明显较低(非常像素化)。如何在保持图像质量的同时导入 PNG 文件?

这是我当前的代码:

from reportlab.pdfgen import canvas
from reportlab.platypus import Image
from reportlab.lib.pagesizes import letter
from PIL import Image

def generatechart(filename):
    c = canvas.Canvas(filename, pagesize=(612,792))
    third = '3B.png'
    tbl = '3BL.png'
    sixh = '6H.png'
    grid = 'grid.png'
    lc = 'LCF.png'
    lf = 'LF.png'
    lfl = 'LFL.png'
    ss = 'SS.png'
    table = 'table.png'
    c.drawImage(third, 86.629, 244.35, width=None, height=None, mask='auto')
    c.drawImage(tbl, 85.042, 272.94, width=None, height=None, mask='auto')
    c.drawImage(sixh, 96.209, 231.464, width=None, height=None, mask='auto')
    c.drawImage(grid, 36.965, 96.518, width=None, height=None, mask='auto')
    c.drawImage(lc, 80.331, 103.487, width=None, height=None, mask='auto')
    c.drawImage(lf, 39.16, 138.452, width=None, height=None, mask='auto')
    c.drawImage(lfl, 36.965, 217.363, width=None, height=None, mask='auto')
    c.drawImage(ss, 104.197, 196.81, width=None, height=None, mask='auto')

    c.showPage()
    c.save()

generatechart('test.pdf')

【问题讨论】:

    标签: python python-imaging-library reportlab


    【解决方案1】:

    你应该做的是在drawImage 方法中指定widthheight 小于原始文件值。例如:如果您的文件是width = 1000px * height = 1000px,您可以使用width = 100 * height = 100 绘制图像。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-20
      • 1970-01-01
      • 2011-11-15
      • 1970-01-01
      • 2011-02-12
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多