How to deal with canvas.toDataURL image/png error
Jan 23, 2018 am 10:43 AMThis time I will bring you canvas.toDataURL image/png error reporting, how to handle canvas.toDataURL image/png error reporting, what are the precautions, the following is a practical case , let’s take a look.
Problem background:
encountered a requirement to take a screenshot of the video being played. The video is played using the video tag, and then the real-time screenshot is captured when the video playback area is clicked. FramePicture.
The code is very simple as follows:
var video = document.getElementById('video'); var canvas = document.getElementById('canvas'); var ctx = canvas.getContext('2d'); var img = document.getElementById('img'); function snapshot() { ctx.drawImage(video,0,0); img.src = canvas.toDataURL('image/png'); } video.addEventListener('click', snapshot, false);
Problem tip:
Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
After review and analysis, we found that this is actually due to the fact that the domain where the video file is located is different from the domain where the picture and page are located, resulting in a cross-domain transmission problem.
Solution:
Put the video file under the domain where the page is located.
I believe you have mastered the methods after reading these cases. For more exciting information, please pay attention to other related articles on the php Chinese website!
Related reading:
How to make mobile web page content adaptive
How to deal with content overflow in the table table
How to obtain the dynamic remaining word count of textarea
The above is the detailed content of How to deal with canvas.toDataURL image/png error. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to set up the keyboard boot function on a GIGABYTE motherboard (enable keyboard boot mode on GIGABYTE motherboard)

How to enable direct connection of independent graphics card on Shenzhou Xuanlong m7e8s3?

How to use Bing Image Creator for free

How to delete images from Xiaomi phones

How to identify genuine and fake shoe boxes of Nike shoes (master one trick to easily identify them)

What is the resolution of Savior y7000p when playing CF (how to adjust the full screen when playing CF on Savior y7000)
