Skip to content

Instantly share code, notes, and snippets.

@shawnmclean
Created December 11, 2012 14:37
Show Gist options
  • Save shawnmclean/4259012 to your computer and use it in GitHub Desktop.
Save shawnmclean/4259012 to your computer and use it in GitHub Desktop.
Code behind for full screen camera view
public partial class CameraView : PhoneApplicationPage
{
private PhotoCamera cam;
public CameraView()
{
InitializeComponent();
activateCamera();
}
private void activateCamera()
{
//You should do all your camera availability checks here first.
cam = new PhotoCamera(CameraType.Primary);
// Event is fired when the PhotoCamera object has been initialized.
cam.Initialized += cam_Initialized;
//Set the VideoBrush source to the camera.
viewfinderBrush.SetSource(cam);
}
void cam_Initialized(object sender, CameraOperationCompletedEventArgs e)
{
if (e.Succeeded)
{
this.Dispatcher.BeginInvoke(delegate()
{
// Use the orientation to determine how to transform the camera preview
previewTransform.Rotation = cam.Orientation ;
var res = cam.AvailableResolutions.FirstOrDefault();
//calculate the dimensions of the canvas to match the aspect ratio that the video feed will be displayed in.
//currently set to max height from xaml, so we need to calculate the width
viewfinderCanvas.Width = (res.Height / res.Width) * viewfinderCanvas.ActualHeight;
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment