Sunday, February 7, 2010

Opening Qt loaded file in PIL

fileName = QtGui.QFileDialog.getOpenFileName(self, self.tr("Open File"),
                                                     QtCore.QDir.currentPath())
pil_img = self.setImage(str(fileName))

def setImage(self, filename):
        "set image to given filename"
        self.filename = filename
        self.pilImg = None
        if not (filename and os.path.exists(filename)):
            return
        
        try:
            pilImg = Image.open(filename)
        except IOError:
            self.writeStatus("Error loading image")
            return
        return pilImg

No comments:

Post a Comment