Windows-8.1

How to choose photo from media library or capture a new one in windows phone app

This is the first blog post of this series in which I am going to tell you about how to choose a image from the phone media gallery and How to capture a new image and display it.

The task that we shall be using is PhotoChooserTask. We shall be using the task complete event handler for this purpose.

 

Different steps involved are

 

1. Create a new project called Photochooser.

 


 

2. Firstly I shall demonstrate you how to choose the image from the existing ones that are there in media library of your phone

 

The namespace required for Launchers and Choosers task is

 

 

Select the existing image

Create a button on the MainPage and add the following code given below in the click event handler of the button to launch a Photochooser task.

 

 

The task has got different properties the important ones are the height and width of the image which we want to select.

The event handler which we need to concentrate on is the Photoresult event handler.

Just below the code of button click event handler add the following code of PhotoResult event handler.

 

 

The code given above will set the image source of image control to that of the image chosen from the media library.

 

3. We can also capture a new image by launching CameraCapturetask

.

Capturing image from camera

Create a new button on the MainPage and add the following code for launching the CameraCapturetask in the click event handler of button.

 

 

This task has got no properties. The event handler which we need to concentrate on is same as that of Photochooser which is PhotoResult.

Just below the code of button click event handler add the following code of PhotoResult event handler.

 

 

The code above will set the image source of image control to that of image you have captures from your camera.

 


 

4. If you have any doubts related to this post you can download the full source project file from the link given below.

 
Download full Project Source file Photochooser.zip
 

5. If you want to save the selected or captured image to isolated storage you can refer to the link of following post given below.


Chetan Gulati

Currently am doing B TECH in IT from Delhi Technological University. App development is my passion. Believe in quality rather than quantity.

  • Reynard Natividad

    Hello? I got squiggly lines on the “Photochooser” statement.. pelase help me with this… is this working on WP8.1?

Read more:
How to create your first Windows Phone app
How to change the App name and Tile name of your Windows phone app
Data binding in Windows Phone app – One way binding
Close