Exemplo n.º 1
0
    def saveImageButtonClicked(self):
        filters = 'Portable Network Graphics (*.png)'
        filters += ';;' + 'Joint Photographic Experts Group (*.jpg)'
        filters += ';;' + 'Windows Bitmap (*.bmp)'
        filters += ';;' + 'Tagged Image File Format (*.tiff)'
        
        filename = QFileDialog.getSaveFileName(
             caption='Save Image As',
             directory='ptchan_image.png',
             filter=filters,
             initialFilter='Portable Network Graphics (*.png)')
        
        # retrieve data from PTchan engine
        data_raw = self.engine.getFilmView().getData()
        data = array('f', data_raw) # this converts data into proper array

        # convert from float in [0.0,1.0] to bytes in [0,255]
        list = []
        for comp in data:
            list.append(int(255.0 * comp))

        # transform list of integers into byte array
        byte_array = array('B', list)
        
        image = QImage(
            byte_array.tostring(),
            self.engine.getFilmView().getWidth(),
            self.engine.getFilmView().getHeight(),
            QImage.Format_RGB888)

        # default mirrored() inverts vertical, exactly what is needed to transform
        # image data from OpenGL coord frame
        image.mirrored().save(filename[0])