Don of the Day

Don of the Day


Adventures in software development with Xamarin and the Web

Software developer, building things with code in sunny Scottsdale, AZ.

Share


Twitter


Windows Phone Image Crop

Don FitzsimmonsDon Fitzsimmons

In my new app, I really wanted to provide the ability for users to crop an image that would be used for a background. I figured I’d have to create a custom control and maybe use the Nokia Imaging SDK and frankly, that sounded like a lot of work so I left this functionality out of my app thinking I’d go back and add it on the next release.

Maybe this is widely know, but it was news to me. To crop an image in the photo chooser on Windows Phone, all you have to do is set the pixel width and height that you want to allow and the crop tool pops up automatically. How cool is that? So easy. But, I searched quite a bit trying to find a solution and couldn’t. Then, I came across a StackOverflow post where someone explained it.

Here’s what the code looks like for the chooser (I’m actually grabbing the device screen size for my width and height).

private void uxPickPhotoClick(object sender, RoutedEventArgs e) { _photoChooserTask = new PhotoChooserTask(); _photoChooserTask.PixelWidth = Convert.ToInt32(screenSize.Width); photoChooserTask.PixelHeight = Convert.ToInt32(screenSize.Height) ; photoChooserTask.Completed += _photoChooserTaskCompleted; _photoChooserTask.Show(); }

That’s it. Once you add the pixel width and height, you get this nice crop tool, allowing users to select where the image should be cropped. I love when things like this are built into the native API.

wp<em>ss</em>20140207_0001

Now the first release of my app will have image cropping.

Software developer, building things with code in sunny Scottsdale, AZ.

Comments