H5 calling the local camera

Source: Internet
Author: User

<! DOCTYPE html>
<meta charset= "UTF-8" >
<title></title>
<script type= "Text/javascript" src= "Http://123.56.106.187:8010/Scripts/listjs/jquery-1.7.2.min.js" ></ Script>
<script>
Determine if the browser supports HTML5 Canvas
Window.onload = function () {
try {
Create a canvas element dynamically and get him 2Dcontext. If an exception occurs, document.createelement ("canvas") is not supported. GetContext ("2d");
document.getElementById ("Support"). InnerHTML = "browser supports HTML5 CANVAS";
}
catch (e) {
DOCUMENT.GETELEMENTBYIDX ("Support"). InnerHTML = "Browser not supported HTML5 CANVAS";
}
};
This generation is mainly to get the video stream of the camera and display it in
Window.addeventlistener ("domcontentloaded", function () {
var canvas = document.getElementById ("Canvas"),
Context = Canvas.getcontext ("2d"),
Video = document.getElementById ("video"),
Videoobj = {"Video": true},
Errback = function (Error) {
Console.log ("Video Capture Error:", Error.code);
};
$ ("#snap"). Click (function () {
Context.drawimage (video, 0, 0, 330, 250);
})
Navigator.getusermedia in opera is like a navigator.getusermedianow.
if (Navigator.getusermedia) {
Navigator.getusermedia (videoobj, function (stream) {
VIDEO.SRC = stream;
Video.play ();
}, Errback);
} else if (Navigator.webkitgetusermedia) {
Navigator.webkitgetusermedia (videoobj, function (stream) {
VIDEO.SRC = Window.webkitURL.createObjectURL (stream);
Video.play ();
}, Errback);
}

}, False);

Upload Server
function Catchcode () {
var Canvans = document.getElementById ("Canvas");
Gets the canvas object for the browser page
The following starts compiling data
var imgdata = Canvans.todataurl ();
Convert an image to Base64 data
var base64data = imgdata.substr (22);
Truncate 22-bit string as image data on the front-end
Begins asynchronously on
$.post ("Uploadimgcode.ashx", {"img": Base64data}, function (data, status) {
if (status = = "Success") {
if (data = = "OK") {
Alert ("Two-dimensional has been resolved");
}
else {
alert (data);
}
}
else {
Alert ("Failed on data");
}
}, "text");
}
</script>
<body>
<div id= "Contentholder" >
<video id= "video" width= "autoplay>" height= "
</video>
<input type= "button" id= "Snap" style= "width:100px;height:35px;" value= "Photo"/>
<canvas style= "id=" Canvas "width=" "height=" >
</canvas>
</div>
</body>

H5 calling the local camera

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.