PyQt4 - 图像水印
我试图打开一个 PNG 图像并通过 QImage 和 QPainter 向其中写入一些文本(水印)。该代码在 Linux 上 100% 运行,但当我在 Windows XP 上运行它时(尚未使用任何其他版本的 Windows 进行测试),文本永远不会写入图像。我的代码位于 try/ except 块中,但没有返回错误。
image = QtGui.QImage('demo.png')
painter = QtGui.QPainter()
painter.begin(image)
painter.setOpacity(0.8)
painter.setPen(QtCore.Qt.blue)
painter.setFont(QtGui.QFont('arial', 12))
painter.drawText(image.rect(), QtCore.Qt.AlignCenter, 'Watermark')
painter.end()
image.save('demo.png')
使用Python 2.6.2,PyQt 4.5.4
有什么想法吗?
I'm trying to open a PNG image and write some text to it (a watermark) via QImage and QPainter. The code works 100% on Linux but when I run it on Windows XP (haven't tested with any other versions of Windows) the text is never written to the image. I have the code in a try/except block, but no errors are returned.
image = QtGui.QImage('demo.png')
painter = QtGui.QPainter()
painter.begin(image)
painter.setOpacity(0.8)
painter.setPen(QtCore.Qt.blue)
painter.setFont(QtGui.QFont('arial', 12))
painter.drawText(image.rect(), QtCore.Qt.AlignCenter, 'Watermark')
painter.end()
image.save('demo.png')
Using Python 2.6.2, PyQt 4.5.4
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我首先想到的可能是它在 Windows 上找不到指定的字体。
First thing that comes to my mind is maybe it isn't finding the specified font on Windows.
我的猜测是,无论您在 Windows 上使用什么 png 库都不会(正确)实现透明度
My guess would be that whatever png lib you are using on Windows doesn't do tranparency (properly)