保存Mipmap文件

时间:2015-12-16 22:28:55

标签: python pyqt pyqt4

所以,我差不多完成了构建创建mipmap的程序。它将成功上传您选择的图像,并创建该图像的mipmap,但现在最后一部分就是我被卡住的地方。

我现在希望用户能够保存他或她的mipmap,但我不确定如何。我希望他们能够将它保存在他们想要的任何地方,我觉得它需要一个dialoq盒子,但我只知道在打开物品时如何实现对话框,而不是保存它们。

到目前为止,这是我的代码:

from __future__ import division
from PyQt4 import QtCore, QtGui, QtOpenGL
from PyQt4.QtGui import * #Used to import QPixmap. DO NOT REMOVE.
from PyQt4.QtCore import * #Used to import Qt.KeepAspectRation. DO NOT REMOVE.
import sys, os
import mmCreator


class MyApp(QtGui.QMainWindow, mmCreator.Ui_MainWindow):
    def __init__(self, parent=None):
        super(MyApp, self).__init__(parent)
        self.setupUi(self)
        self.btnSelect.clicked.connect(self.select_image)
        self.btnConvert.clicked.connect(self.mipmap)
        self.btnDownload.clicked.connect(self.download)


    def select_image(self):
        self.origImage.setAlignment(QtCore.Qt.AlignCenter)
        self.origImage.clear()
        global image
        image = QtGui.QFileDialog.getOpenFileName(self,
                                              "Select Image",
                                              "",
                                              "Image File (*.jpg *.png *.gif)")
        global pixmap
        pixmap = QPixmap(image)
        scaledPixmap = pixmap.scaled(self.origImage.size(), Qt.KeepAspectRatio)
        self.origImage.setPixmap(scaledPixmap)
        self.origImage.show()


    def mipmap(self):
        self.mipMap.setAlignment(QtCore.Qt.AlignCenter)
        #Create scaled versions of the source image.
        pixmap = QPixmap(image)
        global mipmaps
        mipmaps = []
        #Version 1 goes up to 1/16 of original size.
        mipmaps.append(pixmap.scaledToWidth(pixmap.width() / 2))
        mipmaps.append(pixmap.scaledToWidth(pixmap.width() / 4))
        mipmaps.append(pixmap.scaledToWidth(pixmap.width() / 8))
        mipmaps.append(pixmap.scaledToWidth(pixmap.width() / 16))
        #Show the first mipmapped version of the image, at 75% label size.
        scaledMipMap = mipmaps[0].scaled(self.mipMap.size() * (3/4), Qt.KeepAspectRatio)
        self.mipMap.setPixmap(scaledMipMap)
        self.mipMap.show()

    def download():
        mipmaps.save('/path/to/file.png', 'PNG')

def main():
    app = QtGui.QApplication(sys.argv)
    form = MyApp()
    form.show()
    app.exec_()

if __name__ == '__main__':
    main()

0 个答案:

没有答案