In Windows phone silverlight, I use PhotoCamera to get buffer frame when start preview video, in universal app I use MediaCapture instead, but I don't know how to get preview buffer.
Thanks
In Windows phone silverlight, I use PhotoCamera to get buffer frame when start preview video, in universal app I use MediaCapture instead, but I don't know how to get preview buffer.
Thanks
Since Windows Runtime doesn't have Silverlight's
PhotoCaptureDevice
class, the extremely usefulGetPreviewBufferARGB()
andGetPreviewBufferYCbCr()
methods are not available.The solution you're looking for is to use the
MediaCapture.StartPreviewToCustomSinkAsync()
method, but this requires C++ skills better than mine. No-one seems to have solved the problem and shared their code.Now there's a really beautiful solution, using the Lumia Imaging SDK, that doesn't use the MediaCapture class, but will probably solve your problem even better.
Check out Microsoft's example on Github first. This works well but is quite complicated because it targets both Windows 8.1 and Windows Phone 8.1.
I've written some simpler code, just targeting Windows Phone, for my own understanding. It might help.
Start with a new C# Windows Phone 8.1 (Store) app with the Lumia Imaging SDK installed via NuGet PM. This example draws to an image element with
x:Name="previewImage"
inMainPage.xaml
so make sure you add that. You'll also need to make the relevant imports toMainPage.xaml.cs
which I think are.Then you just add the following in the right place in
MainPage.xaml.cs
.You might be wondering... how do I grab the previewBuffer? You don't need to!
The
_writeableBitmap
object always holds the latest frame from the camera so you can do whatever you like with it.My other answer is still valid for Universal Apps targeting Windows 8.1 -- but for those targeting Windows 10 with UWP apps there is a much simpler answer now.
Grabbing a preview frame in UWP is easy and well-documented -- from an existing MediaCapture object it can be done in three lines.