Access from the Browser to Camera

前端 未结 5 1787
别那么骄傲
别那么骄傲 2020-12-13 07:38

I have one question about access to the camera from the browser. (Android and iOS browser)

Google and Apple announced 1 year ago, that the access from the browser to

相关标签:
5条回答
  • 2020-12-13 07:58

    I did using the input, as they said here, and worked really good on iOs. I could get a picture from camera or photo album and set an img element.

    Here is the code: http://jsfiddle.net/2wZgv/

    The js:

    <script>
    
        oFReader = new FileReader();
    
        oFReader.onload = function (oFREvent) {     
            document.getElementById("fotoImg").src = oFREvent.target.result;
            document.getElementById("fotoImg").style.visibility = "visible"; 
            var screenHeight = screen.availHeight;
            screenHeight = screenHeight - 220;
            document.getElementById("fotoImg").style.height = screenHeight;
        };
    
        $(function() {
            $("input:file").change(function (){
                var input = document.querySelector('input[type=file]');
                var oFile = input.files[0];
                oFReader.readAsDataURL(oFile);  
            });
        });
    
    </script>
    

    picture photo album mobile jquery camera

    0 讨论(0)
  • 2020-12-13 08:03

    This is the w3c draft

    After reading it the input tag should be

    <input type="file" accept="image/*" capture="camera" id="capture"> 
    
    0 讨论(0)
  • 2020-12-13 08:08

    try the following:

    <html>
    <body>
    <form>
    <input type="file" accept="image/*;capture=camera"/>
    <input type="submit"/>
    </form>
    </body>
    </html>
    
    0 讨论(0)
  • 2020-12-13 08:10

    Try this stuff.

    <video id="Video" autoplay="autoplay" audio="muted" width="100%" height ="100%"> </video>
    
    <script type="text/javascript">
    if (navigator.getUserMedia) {
        var video = document.getElementById('Video');
        video.src = null;
        navigator.getUserMedia('video', successCallback, errorCallback);
        //if everything if good then set the source of the video element to the mediastream
        function successCallback(stream) {
            video.src = stream;
        }
        //If everything isn't ok then say so
        function errorCallback(error) {
            alert("An error occurred: [CODE " + error.code + "]");
        }
    }
    else {
        //show no support for getUserMedia
        alert("Native camera is not supported in this browser!");
    }
    </script>
    

    But remember this will work only with Opera Mobile for Android. No other browser right now supporting with camera access. Up to my knowledge iOS won't support this feature now, may be in future.

    Thank You.

    0 讨论(0)
  • 2020-12-13 08:20

    This is possible. You can access camera through your browser application. If you are developing through Phone Gap then look for http://docs.phonegap.com/phonegap_camera_camera.md.html

    This is the camera API in PhoneGap to access camera.

    0 讨论(0)
提交回复
热议问题