Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么';t AppMaker图像小部件何时接受照相机快照HTML图像元素?_Javascript_Html_Google App Maker - Fatal编程技术网

Javascript 为什么';t AppMaker图像小部件何时接受照相机快照HTML图像元素?

Javascript 为什么';t AppMaker图像小部件何时接受照相机快照HTML图像元素?,javascript,html,google-app-maker,Javascript,Html,Google App Maker,如果我使用HTML图像代替AppMaker小部件“快照”,那么这段代码就可以正常工作。 使用AppMaker小部件时,除了将图像放入AppMaker图像小部件之外,其他所有操作都会执行 //HTML at startup <video id="stream"top="0" left="0"width="400" height="532"</video> <canvas id="capture" width="200" height="266" ></canva

如果我使用HTML图像代替AppMaker小部件“快照”,那么这段代码就可以正常工作。 使用AppMaker小部件时,除了将图像放入AppMaker图像小部件之外,其他所有操作都会执行

//HTML at startup
<video id="stream"top="0" left="0"width="400" height="532"</video>
<canvas id="capture" width="200" height="266" ></canvas>

//Starts the video stream on-click the AppMaker image widget ‘snapshot’
var capture = document.getElementById( "capture" );
var stream =document.getElementById('stream');
var cameraStream = null;
function startStreaming() {
 var mediaSupport = 'mediaDevices' in navigator;
 if( mediaSupport && null == cameraStream ) {
       navigator.mediaDevices.getUserMedia( { video: true } )
       .then( function( mediaStream ) {
           stream.srcObject = mediaStream;
           stream.play();
       })
       .catch( function( err ) {
           console.log( "Unable to access camera: " + err );
       });
   }
   else {
       alert( 'Your browser does not support media devices.' );
       return;
   }
}
startStreaming(); // displays the camera output in the video window

如果您仅将App Maker小部件命名为“快照”,然后尝试使用getElementById()引用该小部件,那么它在DOM中找不到该小部件,因为App Maker小部件没有id属性,除非您通过代码添加该属性。这是一个假设,但我相信AM使用GetElementsByCassName()[0],这就是为什么任何给定页面上的小部件名称都必须是唯一的。但是,我不确定这是您的问题。var imageWidgets=document.getElementsByClassName(“image”)//警报(“图像小部件的数量=“+imageWidgets.length”);返回0;如何在HTML中添加app Maker小部件“id”?可以使用
widget.getElement().setAttribute('id','snapshot')
。我还没有尝试过这种方法,但我不确定一个图像小部件是否能够像您在这里指定的那样接受DataURL。我知道,在一个html小部件中,有一个如您所述的标记是可能的,您可能希望在captureSnapshot函数中尝试这一点
app.pages.Yourpage.degenders.YourImgWidget.url=capture.toDataURL('image/png')
。如果这不起作用,那么可能是对图像小部件的限制。谢谢你的帮助。
//shutter button on-click script
var capture =document.getElementById('capture');
var stream=document.getElementById("stream");

function captureSnapshot() {  
   var ctx = capture.getContext('2d');
   ctx.drawImage( stream, 0, 0, capture.width, capture.height );
   document.getElementById('snapshot').src=capture.toDataURL("image/png" );
{
captureSnapshot;