【发布时间】:2019-10-21 03:26:20
【问题描述】:
我下面有一些代码应该将 SVG 图像转换为 PNG。它运行时不会出错,但会创建一个空白的 PNG 文件,而不是一个与原始 SVG 具有相同图像的文件。我确实发现这不是 cairo 的错误,而是更多与 rsvg 相关的错误,我得到了here。
import cairo
import rsvg
img = cairo.ImageSurface(cairo.FORMAT_ARGB32, 640,480)
ctx = cairo.Context(img)
handle= rsvghandler.Handle('example.svg')
handle.render_cairo(ctx)
img.write_to_png("svg.png")
我在 Windows 10 上使用 Python 3.6。
我一生都无法弄清楚为什么它没有显示正确的图片。任何帮助将不胜感激。
【问题讨论】:
-
我试图重现您的问题,但我似乎无法安装
cairo。运行pip install cairo时,我得到Could not find a version that satisfies the requirement cairo (from versions: )。运行pip install pycairo时,我收到错误Package cairo was not found in the pkg-config search path.Perhaps you should add the directory containing 'cairo.pc' to the PKG_CONFIG_PATH environment variable。你是怎么得到它的? -
我通过在lfd.uci.edu/~gohlke/pythonlibs 使用
pip install [wheelname]下载 Pycairo whl 文件来安装 cairo。我不记得哪个对我有用,但我必须尝试一些才能正确安装。
标签: python python-3.x type-conversion cairo rsvg