本机代码中的PhotoCaptureDevice

时间:2013-10-18 12:33:53

标签: c# windows-phone-8 windows-phone native-code c++-cx

在Windows Phone 8上,我希望用本机代码拍摄相机,但是我在最后阶段被阻止无法从IOutputStream中提取信息。

在C#中我们编码:

MemoryStream image = new MemoryStream();
MemoryStream imagePreview = new MemoryStream();
cameraCaptureSequence.Frames[0].CaptureStream = image.AsOutputStream();
cameraCaptureSequence.Frames[0].ThumbnailStream = imagePreview.AsOutputStream();
await cameraCaptureSequence.StartCaptureAsync();
从现在开始,

图像流具有捕获图像的信息,我可以渲染它。

在C ++ / Cx中我需要做同样的事情,但要更多,直到捕获捕获图像的字节*,这里是我的代码:

Windows::Phone::Media::Capture::CameraCaptureSequence^ cameraCaptureSequence;
IBuffer^ image;
return concurrency::create_async([this]()
{
    cameraCaptureSequence->Frames->GetAt(0)->CaptureStream = reinterpret_cast<IOutputStream^>(image);
    create_task( m_camera->PrepareCaptureSequenceAsync(cameraCaptureSequence) ).wait();
    create_task( cameraCaptureSequence->StartCaptureAsync() ).then([this]()
    {

    }
}

从最基本的事情开始,我希望了解如何“保存”到IBuffer ^捕获的图像流的结果,更好地获取内部字节*缓冲区。

由于

2 个答案:

答案 0 :(得分:1)

您可以通过ICameraCaptureFrameNative从Native code中捕获的图像访问像素数据。实现接口的对象是通过COM获得的。获得对象后,使用MapBuffer()访问BYTE *数组。

请注意,以这种方式获得的像素数据为NV12 format,而不是人们期望的JPEG或RGB。

   #include <Windows.Phone.Media.Capture.Native.h>

   CameraCaptureFrame^ frame = m_cameraCaptureSequence->Frames->GetAt(0);
   pNativeFrame = NULL;
   HRESULT hr = reinterpret_cast<IUnknown*>(frame)->QueryInterface(__uuidof(ICameraCaptureFrameNative ), (void**) &pNativeFrame);

   create_task( m_camera->PrepareCaptureSequenceAsync(m_cameraCaptureSequence) ).wait();
   create_task( m_cameraCaptureSequence->StartCaptureAsync() ).then([this]()
   {
         DWORD bufferSize =0;
         BYTE * pBuffer = NULL;
         pNativeFrame->MapBuffer(&bufferSize, &pBuffer); // Pixels are in pBuffer. 
         // Unmap() the buffer before capturing another image.

答案 1 :(得分:0)

ICameraCaptureFrameNative无法访问包含预览的纹理吗?

如果您想从IBuffer获取访问数据,请查看此处:http://msdn.microsoft.com/en-us/library/windows/apps/dn182761.aspx

对于您的情况,我认为您需要一个实现IOutputStream的类。也许InMemoryRandomAccessStream