Capture image in HTML5

Introduction: Hello Guys, “Welcome back” Today i am here with another one new great article. In this article I will explain about how to capture image with webcam using jQuery in HTML5.

Code for HTML Page

On the HTML page i will create a table with two columns and three rows by using <tr> <td>. On the first’s column of the first row i write the title as Live Camera and on the second column of the same row I write the titles as Captured Image. On the first’s column of the second row I place a div with the id named webcam and on the second column of the second row I place a img tag with the id named imgCapture. And on the first’s column of the third row I place a button with the id named btnCapture. On the click of buttom user can capture the picture or image by using webcam.  On the HTML page I inherited the two js files with the named jquery.min.js and webcam.js respectively.

Here i am giving complete code for HTML page. You can copy and paste the whole code on your HTML page for enjoys the exaction of the code.

 <!DOCTYPE html>

<html>

<head>

    <meta charset="utf-8" />

    <title></title>

    <style type="text/css">

        body { font-family: Arial; font-size: 10pt; }

        table { border: 1px solid #ccc; border-collapse: collapse; }

        table th { background-color: #F7F7F7; color: #333; font-weight: bold; }

        table th, table td { padding: 5px; border: 1px solid #ccc; }

        table, table table td { border: 0px solid #ccc; }

    </style>

</head>

<body>

    <table border="0" cellpadding="0" cellspacing="0">

        <tr>

            <th align="center"><u>Live Camera</u></th>

            <th align="center"><u>Captured Image</u></th>

        </tr>

        <tr>

            <td><div id="webcam"></div></td>

            <td><img id="imgCapture" /></td>

        </tr>

        <tr>

            <td align="center">

                <input type="button" id="btnCapture" value="Capture" />

            </td>

            <td align="center"></td>

        </tr>

    </table>

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/webcamjs/1.0.26/webcam.js"></script>

    <script src="WebCam.js" type="text/javascript"></script>

    <script type="text/javascript">

        $(function () {

            Webcam.set({

                width: 320,

                height: 240,

                image_format: 'jpeg',

                jpeg_quality: 90

            });

            Webcam.attach('#webcam');

            $("#btnCapture").click(function () {

                Webcam.snap(function (data_uri) {

                    $("#imgCapture")[0].src = data_uri;

                });

            });

        });

    </script>

</body>

</html>

Conclusion: In above code, I explained that how to capture image with webcam using jQuery in HTML5. This code is very helpful for every developer. Bye Bye and take care of yourself Developers. We will come back shortly with the new article.

 

Regards

Using Asp.net

 

Comments

Popular posts from this blog

Sending reset password link for one time use only in asp.net

add delete update inside gridview using store procedure in ASP.NET

Change password using asp.net