将reportlab对象转换为PIL的最佳方法是什么

时间:2020-06-09 09:52:36

标签: python-3.x python-imaging-library reportlab

我有一个reportLab对象(reportlab.graphis.shapes.Drawing),我正在尝试将其转换为PIL.Image.Image 问题是我失去了很多图像质量。 PDF上的相同reportLab对象要比ImageViewer中的图像好得多。如何获得更好的质量图像。预先感谢。

下面是我的代码:

from PyQt5 import QtWidgets, QtGui
from PyQt5.QtWidgets import (QApplication, QMainWindow)
from PyQt5.QtCore import Qt

from reportlab.graphics.charts.piecharts import Pie
from reportlab.graphics.shapes import *

from PIL import ImageQt

from reportlab.graphics import renderPM

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.resize(800, 600)

        dockWidget = QtWidgets.QDockWidget()
        dockWidget.setWindowTitle("Image Viewer")

        d = Drawing(200, 150)
        pc = Pie()
        pc.x = 0
        pc.y = 0
        pc.width = 100
        pc.height = 100
        pc.data = [10, 20, 30, 40, 50, 60]
        pc.labels = ['a', 'b', 'c', 'd', 'e', 'f']
        pc.slices.strokeWidth = 0.5
        pc.slices[3].popout = 10
        pc.slices[3].strokeWidth = 2
        pc.slices[3].strokeDashArray = [2, 2]
        pc.slices[3].labelRadius = 1.75
        pc.slices[3].fontColor = colors.red
        d.add(pc)

        test = renderPM.drawToPILP(d)

        QtImage1 = ImageQt.ImageQt(test)
        QtImage2 = QtGui.QImage(QtImage1)
        pixmap = QtGui.QPixmap.fromImage(QtImage2)
        label = QtWidgets.QLabel('testing', self)
        label.setPixmap(pixmap)
        dockWidget.setWidget(label)

        dockWidget.setFloating(False)
        self.addDockWidget(Qt.RightDockWidgetArea, dockWidget)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    myWidget = MainWindow()
    myWidget.show()

    sys.exit(app.exec_())

0 个答案:

没有答案