Beispiel #1
0
    def getQImage(self, resX=None,resY=None):
        #zoom the the chosen colorrange:
        r = self.ui.histogram.region.getRegion()
        self.ui.histogram.vb.setYRange(*r)
        #create ImageExporters:
        mainExp = ImageExporter(self.view)
        colorAxisExp = ImageExporter(self.ui.histogram.axis)
        colorBarExp = ImageExporter(self.ui.histogram.gradient)

        if resX or resY:
            #get size-x:
            mainW = mainExp.getTargetRect().width()
            colorAxisW = colorAxisExp.getTargetRect().width()
            colorBarW = colorBarExp.getTargetRect().width()

            #all parts have the same height:
            mainExp.parameters()['height'] = resY
            colorAxisExp.parameters()['height'] = resY
            colorBarExp.parameters()['height'] = resY
            #size x is proportional:
            sumWidth = mainW + colorAxisW + colorBarW
            mainExp.parameters()['width'] = resX * mainW / sumWidth
            colorAxisExp.parameters()['width'] = resX * colorAxisW / sumWidth
            colorBarExp.parameters()['width'] = resX * colorBarW / sumWidth
        #create QImages:
        main =mainExp.export(toBytes=True)
        colorAxis =colorAxisExp.export(toBytes=True)
        colorBar = colorBarExp.export(toBytes=True)
        #define the size:
        x = main.width() + colorAxis.width() + colorBar.width()
        y = main.height()
        #to get everything in the same height:
        yOffs = [0,0.5*(y-colorAxis.height()),0.5*(y-colorBar.height())]
        result = QtGui.QImage(x, y ,QtGui.QImage.Format_RGB32)

        #the colorbar is a bit smaller that the rest. to exclude black lines paint all white:

        result.fill(QtCore.Qt.white)
        painter = QtGui.QPainter(result)
        posX = 0
        for img,y in zip((main,colorAxis,colorBar),yOffs):
            #draw every part in different positions:
            painter.drawImage(posX, y, img)
            posX += img.width()
        painter.end()
        return result