英文:
python skia save skia.DynamicMemoryWStream to svg file
问题
短而言之,以下代码可以提供上下文:
import skia
stream = skia.DynamicMemoryWStream()
...
还有更多对 stream
变量的操作,但它们不重要,关键是我想将 stream
转换为SVG文件。我查看了Python skia库的文档,但它们写得很差,我无法找到实现这个目标的方法。
英文:
in short, the following code can give the context:
import skia
stream = skia.DynamicMemoryWStream()
...
There are more operations done over the stream
variable, but they are not important and the key thing here is I want to convert the stream
to an SVG file. I have looked Python skia library documentation, however, their documentation is poorly written and I wasn't able to find out a way to do so.
答案1
得分: 1
我找到了解决方法。
假设你有一个变量 stream
,其中包含数据并且是 DynamicMemoryWStream
类,那么你首先需要将数据转移到 FileWStream
类,然后使用 FileWStream
将数据转移到 svg 文件。具体步骤如下:
- 创建一个空的 svg 文件,例如命名为
example.svg
- 使用以下代码创建与文件的流
file_stream = skia.FILEWStream("example.svg")
- 从流写入文件流
stream.writeToStream(file_stream)
- 最后刷新文件流,以便将所有接收到的数据写入文件
file_stream.flush()
英文:
I figured out how to solve it.
Say you have a variable stream
which is contain the data and is DynamicMemoryWStream
class, then you first need to transfer the data into class FileWStream
, then you use FileWStream
to transfer the data into the svg file. To be more specific, do the following:
- create an empty svg file, say name it
example.svg
- create stream to the file with following code
file_stream = skia.FILEWStream("example.svg")
- write from stream to file stream
stream.writeToStream(file_stream)
- Finally flush the file stream so it write all data received to the file
file_stream.flush()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论