Crop Selected Image in Windows Phone 8

To crop selected image in the PhotoChooserTask all you have to do is set the pixel height and width of the image that you want to crop.

Let us see the steps to perform this task.

Create new project and once everything is ready write the following code:

  1. PhotoChooserTask open = new PhotoChooserTask();  
  2. open.PixelHeight = 50;  
  3. open.PixelWidth = 50;  
  4. open.Completed += open_Completed;  
  5. open.Show();  
  6.   
  7. void open_Completed(object sender, PhotoResult e)  
  8. {  
  9.    BitmapImage image = new BitmapImage();  
  10.    image.SetSource(e.ChosenPhoto);  
  11.    cropedImage.Source = image;  
  12. }  
Now you can see that the crop option will show while selecting image from gallery like the following screenshot:

crop

That’s it. Once you add the pixel width and height, you will get this nice crop tool, allowing users to select where the image should be cropped.

Now while choosing the picture let us see how to provide camera option.

Write the following code snippet.
  1. PhotoChooserTask open = new PhotoChooserTask();  
  2. open.PixelHeight = 50;  
  3. open.PixelWidth = 50;  
  4. open.ShowCamera = true;  
  5. open.Completed += open_Completed;  
  6. open.Show();  
Just set ShowCamera to true and captured image will automatically get saved to camera roll.

choose picture