Created
December 11, 2012 14:37
-
-
Save shawnmclean/4259012 to your computer and use it in GitHub Desktop.
Code behind for full screen camera view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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