Working with PhotoChooserTask in Windows Phone

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.

Abhishek Sur

Abhishek Sur is a Microsoft MVP since year 2011. He is an architect in the .NET platform. He has profound theoretical insight and years of hands on experience in different .NET products and languages. He leads the Microsoft User Group in Kolkata named KolkataGeeks, and regularly organizes events and seminars in various places for spreading .NET awareness. He is associated with the Microsoft Insider list on WPF and C#, and is in constant touch with product group teams. He blogs at http://www.abhisheksur.com His Book : Visual Studio 2012 and .NET 4.5 Expert Development Cookbook. Follow Abhishek at Twitter : @abhi2434

2 Comments to “Working with PhotoChooserTask in Windows Phone”

Comments are closed.