- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to copy the content of one HTML5 Canvas to another Canvas locally?
The drawImage() method is used to draw image, canvas and videos on canvas. It can also draw part of image and increase or decrease the image size.
Let us see an example −
//context grabbed from your destination canvas ctx = destinationCanvas.getContext('2d'); //drawImage() called passing the source canvas directly dCtx.drawImage(sourceCanvas, 0, 0);
In this code, firstly the image is copied from the source canvas. The sourceCanvas can be a HTMLImageElement, HTMLVideoElement, or a HTMLCanvasElement. A canvas drawing context cannot be used as a source. If a canvas drawing context is your source canvas then there is a reference to the original canvas element on the context under context.canvas
The latter code uses drawImage() method to copy context from source canvas to the desired canvas.
- How to center canvas in HTML5?
- Translating HTML5 canvas
- HTML5 Canvas distorted
- HTML5 Canvas Transformation
- HTML5 Canvas to PNG File
- HTML5 Canvas fit to window
- How to detect point on canvas after canvas rotation in HTML5
- How to draw lines using HTML5 Canvas?
- How to use images with HTML5 canvas?
- HTML5 Canvas Font Size Based on Canvas Size
- How to save HTML5 canvas data to file?
- Zoom HTML5 Canvas to Mouse Cursor
- HTML5 Canvas Transformation Matrix
- HTML5 Canvas Circle Text
- HTML5 Canvas Degree Symbol