Even though we have CameraCapture Task to deal with camera, there is another Chooser available as well, which can take Picture either from MediaLibrary or directly from Camera. The PhotoChooserTask helps in getting an image from the Picture / Media Library locations. The PhotoChooserTask, just like any other Tasks is listed under namespace Microsoft.Phone.Tasks and is inherited from ChooserBase<PhotoResult>, this will ensure that the Task is invoked as a Chooser and the result will be received by the Completed event when choice is made, just similar to CameraCapture.
var photoChooserTask = new PhotoChooserTask(); photoChooserTask.Completed += (s, e)=>{ if(e.TaskResult == TaskResult.OK) { myImage.Source = new BitmapImage(new Uri(e.OriginalFileName)); } }; photoChooserTask.Show();
The above code will show the photoChooserTask and upon selecting the Photo, it will show the picture on myImage control placed on the XAML.
PhotoChooser also allows you to specify ShowCamera, which can invoke the CameraCaptureTask directly from inside of the PhotoChooserTask and select the Photo Captured from camera.
photoChooserTask.ShowCamera = true;
Other than that, you can also set the maximum PixelHeight and PixelWidth of the image choosen from the PhotoChooser. For instance,
photoChooserTask.PixelHeight = 50; photoChooserTask.PixelWidth = 50;
I hope this code will help. Thank you for reading.
Pingback: Windows Store App Developer Links – 2013-11-19 | Dan Rigby
Pingback: Working with PhotoChooserTask in Windows Phone