Use HTML5 drawing technology to call the camera to take pictures;

Source: Internet
Author: User

Calling the phone camera in the MUI frame to take a photo can directly use the HTML5 of the soundtrack;

Here is the HTML code

<video id= "video" width= "640" height= "480" autoplay></video>   <!--This is the screen that is rendered after the camera is called-->< Button id= "Snap" >snap photo</button>   <!--camera button--><canvas id= "Canvas" width= "640" height= "480" ></canvas><!--This line is displayed on the page after taking the picture--

Here's the JavaScript code

var Avideo=document.getelementbyid (' video '); var acanvas=document.getelementbyid (' canvas '); var ctx= Acanvas.getcontext (' 2d '); Navigator.getusermedia  = Navigator.getusermedia | |                          Navigator.webkitgetusermedia | |                          Navigator.mozgetusermedia | |                          navigator.msgetusermedia;//Gets the Media object (this refers to      the camera) Navigator.getusermedia ({video:true}, Gotstream, nostream);// Parameter 1 Gets the user open permission, the parameter two successfully opened after the call, and pass a video stream object, parameter three open failed call, pass error message function Gotstream (stream) {video.src = Url.createobjecturl ( stream); video.onerror = function () {  stream.stop ();}; stream.onended = Nostream;video.onloadedmetadata = function () {  alert (' Camera opened successfully! ‘);};} function Nostream (err) {        alert (err);      } The button simulates the picture by drawing the captured picture onto the canvas document.getElementById ("Snap"). AddEventListener ("click", Function () {Ctx.drawimage ( Avideo, 0, 0, 640, 480);//will get the video drawn on the canvas});

  

Use HTML5 drawing technology to call the camera to take pictures;

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.