Secondary Canvas drawing and secondary canvas drawing

Source: Internet
Author: User

Secondary Canvas drawing and secondary canvas drawing

For Canvas plotting, you can use the toDataURL () method to save the drawn image, and then provide it to the object element for secondary use.

<P> Canvas plotting </p> <canvas id = "mycanvas" width = "300" height = "150"> </canvas> <p> restore plotting </p> <object type = "image/png" id = "myimage"> </object>

Js Processing

<Script type = "text/javascript"> var canvas = document. getElementById ("mycanvas"); if (canvas & canvas. getContext) {var cxt = canvas. getContext ('2d '); cxt. fillStyle = "# FF0000"; cxt. fillRect (,);} var url = canvas. toDataURL (); // return the base64 encoded data of the image. You can also upload a MIME-Type format, such as image/png var img = document. getElementById ("myimage"); img. data = url; // restore the image. MIME is specified. You can also use the src attribute. </script>

Result:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.