How can we run camera as background view in windows phone 8?

282 Views Asked by At

I would like to test around a bit with augmented reality.How to get the picture that comes from the camera as background for my view? For what I want to do, I don't need to access the picture, I just need it as background.

1

There are 1 best solutions below

2
On

You can get the preview-buffer from the camera from the page. We need this to capture a QR-Code without taking pictures with the camera.

Initialize the camera object

_phoneCamera = new PhotoCamera();
_phoneCamera.Initialized += CamInitialized;

In the Initialized - Event. Just create the buffer

private void CamInitialized(object sender, CameraOperationCompletedEventArgs e)
{
    _previewBuffer = new WriteableBitmap((int)_phoneCamera.PreviewResolution.Width, (int) _phoneCamera.PreviewResolution.Height);
}

Ant then you can take everytime a snapshot of the current view:

//grab a camera snapshot
_phoneCamera.GetPreviewBufferArgb32(_previewBuffer.Pixels);
_previewBuffer.Invalidate();

And then you can do what you want with this WriteableBitmap (show as background, or whatever).

Or (if I misunderstood your question) here a link with the info, how to add the camera-view to your page (this is also needed for the above solution): How to create a base camera app for Windows Phone 8