QWebView 欠采样 SVG 渲染
我想使用 QWebView 进行 SVG 缩略图工作,因为它支持过滤器(与仅支持 SVG Tiny 1.2 的 QSvgRender 不同)。除了字体渲染之外,它似乎工作得很好,但可以使用 fontconfig 包进行调整。问题在于它似乎是带有滤波器的欠采样元素。没有滤镜的元素看起来不错且清晰,而带有滤镜的元素则像素化且模糊。
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtSvg import *
from PyQt4.QtWebKit import *
import sys
import time
if __name__ == '__main__':
app = QApplication(sys.argv)
data = open('/home/xxx/workspace/yyy/zzz/out.svg').read()
# svg = QSvgRenderer(QByteArray(data))
qim = QImage(int(1024), int(768), QImage.Format_ARGB32)
web = QWebView()
web.setRenderHint(QPainter.SmoothPixmapTransform)
web.setRenderHint(QPainter.Antialiasing)
web.setRenderHint(QPainter.TextAntialiasing)
painter = QPainter()
def load_finished(ok):
web.resize(1024,768)
painter.begin(qim)
# svg.render(painter)
web.render(painter)
painter.end()
print "null:", qim.isNull()
qim.save('test2.png')
sys.exit()
web.connect(web, SIGNAL('loadFinished(bool)'), load_finished)
web.load(QUrl('file:///home/xxx/workspace/yyy/zzz/out.svg'))
sys.exit(app.exec_())
Qt 4.7。使用 Inkscape、rsvg 或在 Chrome、Firefox 中渲染时,相同的 SVG 文件看起来不错。
I'd like to use QWebView for an SVG thumbnailing job because it supports filters (unlike QSvgRender which only supports SVG Tiny 1.2). It seems to work quite well except for font rendering but that can be tweaked using fontconfig package. The problem is that it seems to be undersampling elements with filters. Elements without filters look good and sharp, while those with filters are pixelated and blurry.
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtSvg import *
from PyQt4.QtWebKit import *
import sys
import time
if __name__ == '__main__':
app = QApplication(sys.argv)
data = open('/home/xxx/workspace/yyy/zzz/out.svg').read()
# svg = QSvgRenderer(QByteArray(data))
qim = QImage(int(1024), int(768), QImage.Format_ARGB32)
web = QWebView()
web.setRenderHint(QPainter.SmoothPixmapTransform)
web.setRenderHint(QPainter.Antialiasing)
web.setRenderHint(QPainter.TextAntialiasing)
painter = QPainter()
def load_finished(ok):
web.resize(1024,768)
painter.begin(qim)
# svg.render(painter)
web.render(painter)
painter.end()
print "null:", qim.isNull()
qim.save('test2.png')
sys.exit()
web.connect(web, SIGNAL('loadFinished(bool)'), load_finished)
web.load(QUrl('file:///home/xxx/workspace/yyy/zzz/out.svg'))
sys.exit(app.exec_())
Qt 4.7. Same SVG file looks OK when rendered using Inkscape, rsvg or in Chrome, Firefox.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 QWebPage(非 GUI 渲染器)进行渲染,看看是否有帮助。我看不到任何会影响渲染的设置。
代码将是这样的(未检查):
Try rendering using QWebPage (the non-GUI renderer), see if that helps. I can't see any setting that would affect the rendering.
Code would be something like this (not checked):