QML Canvas saves canvas content

Author: Yiqu, Ersanli
Personal Wechat ID: iwaleon
Wechat Official Account: Efficient Programmer

I don't know if you have thought about it, we have finally drawn various graphics on the Canvas, how to save it? For example, we implemented a drawing board. After the user completes his own work, do he want to save it to share with others or edit it later by himself?

To achieve this function, Canvas provides two methods:

method describe
string toDataURL(string mimeType) Convert the image in the current canvas to dataURL (the default mimeType is "image/png")
bool save(string filename, size imageSize = undefined) Save the content of the current canvas to the image file filename (the saved format is automatically determined by the file extension), and return true if successful. If imageSize is specified, the resulting image will have this size and a devicePixelRatio of 1.0. Otherwise, the devicePixelRatio() of the window the canvas is in will be applied to the saved image.

The complete mind map is as follows:

おすすめ

転載: blog.csdn.net/u011012932/article/details/131537197