Is there any way, for creating a videobrush that will be on the whole screen, exactly like the default camera app on windows phone 8?
0
votes
1 Answers
0
votes
Yes. There's a lot of examples online of how to do this. The best one I found was this one. I'll copy the relevant portions here. Effectively you just need to create a canvas and hook into the camera. The linked article will give you more information. You'll also need to play with your app permissions so the camera (and front facing camera if applicable) are accessible.
Creating the canvas:
<Canvas x:Name="viewfinderCanvas" Width="640" Height="480">
<Canvas.Background>
<VideoBrush x:Name="viewfinderBrush">
<VideoBrush.RelativeTransform>
<CompositeTransform
x:Name="viewfinderTransform"
CenterX="0.5"
CenterY="0.5"/>
</VideoBrush.RelativeTransform>
</VideoBrush>
</Canvas.Background>
</Canvas>
In your code behind, to set up the hooks:
// Using statements
using Microsoft.Devices;
using Microsoft.Xna.Framework.Media;
// Class Variables
PhotoCamera cam;
MediaLibrary library = new MediaLibrary();
// Event hooks
protected override void OnNavigatedTo
(System.Windows.Navigation.NavigationEventArgs e)
{
if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true)
{
cam = new PhotoCamera(CameraType.Primary);
cam.CaptureImageAvailable +=
new EventHandler<Microsoft.Devices.ContentReadyEventArgs>
(cam_CaptureImageAvailable);
viewfinderBrush.SetSource(cam);
}
else
{
txtMessage.Text = "A Camera is not available on this device.";
}
}
protected override void OnNavigatingFrom
(System.Windows.Navigation.NavigatingCancelEventArgs e)
{
if (cam != null)
{
cam.Dispose();
}
}