简体   繁体   中英

Convert to Image or use canvas?

Just wondering if its better to convert a canvas drawing to an image before adding it to the DOM or is it better to just add the canvas itself?

I am using canvas to create the image.

It depends on your scenario.

Canvas may or may not allocate an extra memory buffer but typically shares the back buffer with the display buffer. This may not be the case if the pixel ratio is different from 1:1 (ie. retina displays).

Also, with canvas, if created using html tags, may be cleared by the browser under certain conditions such as window resize. This seem to be a lesser problem now though then it used to be (Chrome could also clear canvas when showing some dialogs).

Converting it to image gives an performance and memory overhead though: first to create the compressed image, then converting it to base-64 with additional 33% memory overhead, then pass it in as image source which triggers converting of the base-64 string into image file and then for decompressing it to bitmap.

sure convert it to image and add it as DOM object

if you resize canvas will clear itself ,then you will have empty area.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM