捕获基座64中的websocket的图像

时间:2016-01-25 20:40:15

标签: javascript

我有一台连接到GoPro摄像头的服务器,它以base64格式发送图像,可以在localhost上看到,现在我需要捕获截图,但我不能,有什么想法吗?



<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" charset="utf-8">
    var flag = false;
    var imgArray = new Array();
 

      $(document).ready(function(){
         if ("WebSocket" in window) {
            var ws_path = 'ws://' + window.location.host + window.location.pathname + 'ws';
            //alert(ws_path);
            var ws = new WebSocket (ws_path);
            //alert(ws);
            ws.onopen = function () {
               ws.send(1);
            };
            ws.onmessage = function (msg) 
            {
               $("#cam").attr('src', 'data:image/jpg;base64,' + msg.data);
                   if ( flag == true) 
                    {
                        $("#img").attr('src', 'data:image/jpg;base64,' + msg.data);
                        flag = false; 
                        var url = img.src.replace('data:image/jpg;base64,' + msg.data);
                    }
               ws.send(1);
            };
            ws.onerror = function (e) {
               console.log(e);
               ws.send(1);
            };
         } else {
             alert("WebSocket no soportado");
         }
      });
 
      function capture() 
      {
            flag = true;
      };
 

 
</script>
&#13;
<body>
 
  <div id="video"><center>
      <H1>Video caputado desde Go Pro</H1>
        <img id="cam" src=""/><br>
     <button id="capture" onclick="capture();" type="button">Screen Shot</button> 
  </div>
 
  <div id="screenshot">
      <h2><center>Capturas tomadas</h2>
      <img id="url" src="" /><br>
  </div>
 
   <a id="acapture" href="" download="" style="display : none"></a>     
 

  </body>
&#13;
&#13;
&#13;

0 个答案:

没有答案