【问题标题】:How can I use PySide to quickly resize a PNG?如何使用 PySide 快速调整 PNG 的大小?
【发布时间】:2015-09-18 22:25:44
【问题描述】:

我正在尝试制作一个小函数,该函数将获取已渲染为所需大小两倍的缩略图,并使用抗锯齿调整它的大小,以便生成漂亮的平滑缩略图。

这是我目前得到的:

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)

问题是当我调用 bitmap.scaled 时,像素图的大小似乎没有改变 - 我在这里遗漏了一些明显的东西吗?

【问题讨论】:

    标签: python image qt user-interface pyside


    【解决方案1】:

    我以前没有使用过 PySide,但 .scaled 会进行就地替换。文档似乎建议它返回一个新的 QPixmap,您的代码没有保存它。

    也许这会有所帮助:

    bitmap=bitmap.scaled(QtCore.QSize(outSize, outSize),aspectMode=QtCore.Qt.KeepAspectRatio,     mode=QtCore.Qt.SmoothTransformation)
    

    【讨论】:

    • 解决了!我应该早点发现 :D 谢谢你的帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-18
    • 2015-06-02
    • 1970-01-01
    • 2014-02-17
    • 2020-03-30
    • 1970-01-01
    相关资源
    最近更新 更多