CodeByte

Write your code smartly

Tag Archives: WP& Camera

Using Camera in Windows Phone

Here i will tell you how to invoke Camera in Windows phone application. Its as simple as you can use a camera in your cell phone.

So now add a button any where in your Windows Phone application from toolbox and double click it to get the click event handler or find the click event from its properties windows show in previous posts.

Please add the following namespace on top of your CS file or code file

using Microsoft.Phone.Tasks;

Add following code on the click event of the button.

private void button1_Click(object sender, RoutedEventArgs e)
{
   CameraCaptureTask cmt = new CameraCaptureTask();
   cmt.Completed += new EventHandler<PhotoResult>(cmt_Completed);
   cmt.Show();
}

The Camera will be launched after clicking button with a dummy Black object moving around a white screen. by pressing the Capture button you can capture the image. You can Play with the image captured in your application like displaying it on image control.

Put the below code in Camera photo result event

void cmt_Completed(object sender, PhotoResult e)
{
   //throw new NotImplementedException();
   BitmapImage bi = new BitmapImage();
   bi.SetSource(e.ChosenPhoto);
   image1.Source = bi;
}

Enjoy Happy Coding !

Design a site like this with WordPress.com
Get started