Home Web Front-end HTML Tutorial How to deal with canvas.toDataURL image/png error

How to deal with canvas.toDataURL image/png error

Jan 23, 2018 am 10:43 AM
image how

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!

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

Hot Article

Hot Article

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to set up the keyboard boot function on a GIGABYTE motherboard (enable keyboard boot mode on GIGABYTE motherboard) How to set up the keyboard boot function on a GIGABYTE motherboard (enable keyboard boot mode on GIGABYTE motherboard) Dec 31, 2023 pm 05:15 PM

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

How to roll back version in Win11? How to roll back version in Win11? Jun 30, 2023 pm 05:21 PM

How to roll back version in Win11?

How to enable direct connection of independent graphics card on Shenzhou Xuanlong m7e8s3? How to enable direct connection of independent graphics card on Shenzhou Xuanlong m7e8s3? Jan 04, 2024 am 09:24 AM

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

How to use Bing Image Creator for free How to use Bing Image Creator for free Feb 27, 2024 am 11:04 AM

How to use Bing Image Creator for free

How to delete images from Xiaomi phones How to delete images from Xiaomi phones Mar 02, 2024 pm 05:34 PM

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) How to identify genuine and fake shoe boxes of Nike shoes (master one trick to easily identify them) Sep 02, 2024 pm 04:11 PM

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) What is the resolution of Savior y7000p when playing CF (how to adjust the full screen when playing CF on Savior y7000) Jan 07, 2024 am 10:13 AM

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

How to install vc runtime library How to install vc runtime library Feb 21, 2024 am 10:30 AM

How to install vc runtime library

See all articles