2016-11-04 13 views
0

我使用WinJs创建一个应用程序,使用JavaScript获取相机预览。 预览我得到一个videoframe,但现在我想获得所有像素rgba数据来计算平均颜色和其他信息。 我使用Media.Capture类的getPreviewFrameAsync方法。这样对吗?在这些类的JavaScript的Windows应用程序:从JavaScript预览框中获取像素数据

mediaCapture.getPreviewFrameAsync(videoFrame) 
 
    .then(function (currentFrame) { 
 
     //get pixeldata rgba of frame of camerapreview 
 
      
 
    }

文档是非常差.... 感谢。

IngD

回答

0

我使用Media.Capture类的getPreviewFrameAsync方法。这样对吗?

是的,用这个你可以得到一个videoframe的对象。之后,您可以通过VideoFrame.SoftwareBitmap属性获取包含像素数据的SoftwareBitmap对象。类似的代码如下:

return oMediaCapture.getPreviewFrameAsync(videoFrame) 
.then(function (currentFrame) { 
    // Collect the resulting frame 
    var frameBitmap = currentFrame.softwareBitmap; 
    // Show the frame information 
    frameInfoTextBlock.textContent = frameBitmap.pixelWidth + "x" + frameBitmap.pixelHeight + " " + 
     stringOfEnumeration(Windows.Graphics.DirectX.DirectXPixelFormat, frameBitmap.bitmapPixelFormat); 

官方样片CameraGetPreviewFrame提供写在JavaScript语言的例子,它有关于你想你可以参考的特征的例子。

相关问题