Recent Posts
- November 2014 (1)
- January 2014 (1)
- October 2013 (1)
- May 2013 (1)
- February 2013 (2)
- October 2012 (1)
- August 2012 (1)
- July 2012 (4)
- June 2012 (13)
Blog Stats
- 36,360 hits
Write your code smartly
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 !