Question

On Windows Phone 8, I wish to take a camera shot in native code, but I'm blocked on the final stage not being able to extract information from IOutputStream.

in C# we code:

MemoryStream image = new MemoryStream();
MemoryStream imagePreview = new MemoryStream();
cameraCaptureSequence.Frames[0].CaptureStream = image.AsOutputStream();
cameraCaptureSequence.Frames[0].ThumbnailStream = imagePreview.AsOutputStream();
await cameraCaptureSequence.StartCaptureAsync();

from now image stream has information of captured image and I can render it.

In C++ / Cx I need to do the same thing but more until to catch the byte* of captured image, here my code:

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]()
    {

    }
}

Starting from the most basic thing I wish to understand how to "save" into an IBuffer^ the result of captured image stream, better how to get the internal byte* buffer.

Thanks

Était-ce utile?

La solution

You can access the pixel data from a captured image in Native code through the ICameraCaptureFrameNative. The object that implements the interface is obtained through COM. Once you have obtained the object, use MapBuffer() to access the BYTE * array.

Note that the pixel data obtained this way is in NV12 format, not a JPEG or RGB as one would expect.

   #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.

Autres conseils

ICameraCaptureFrameNative doesn't give access to a texture containing the preview?

If you want acces data from a IBuffer look here : http://msdn.microsoft.com/en-us/library/windows/apps/dn182761.aspx

For your case, i thinks you need a class which implement IOutputStream. Maybe InMemoryRandomAccessStream ?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top