Issue
I'm trying to make a small function that will take a thumbnail that has been rendered at twice the required size and resize it with anti-aliasing so that the result is a nice smooth thumbnail.
This is what I've got so far:
from PySide import QtGui, QtCore
def resizeImage(image, outSize):
bitmap = QtGui.QPixmap(image)
bitmap.scaled(QtCore.QSize(outSize, outSize),aspectMode=QtCore.Qt.KeepAspectRatio, mode=QtCore.Qt.SmoothTransformation) # original is larger than this
print bitmap.size()
file = QtCore.QFile(image)
file.open(QtCore.QIODevice.WriteOnly)
bitmap.save(file)
file.close()
resizeImage("image.png", outSize = 256)
The problem is the size of the pixmap doesn't seem to change when I call bitmap.scaled - am I missing something obvious here?
Solution
I've not used PySide before, but does .scaled do an in-place substitution. The documentation seems to suggest that it returns a new QPixmap, which your code is not saving.
Maybe this would help:
bitmap=bitmap.scaled(QtCore.QSize(outSize, outSize),aspectMode=QtCore.Qt.KeepAspectRatio, mode=QtCore.Qt.SmoothTransformation)
Answered By - Dr Xorile
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.