How to deal with canvas.toDataURL image/png error

php中世界最好的语言
Release: 2018-01-23 10:43:25
Original
2739 people have browsed it

This 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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!