Microsoft.Devices.PhotoCamera change camera resolution

I’ve been having some fun building an app for my Windows Phone this weekend using Azure Mobile Services. I wanted to do some stuff with photos as well by uploading them to Azure Storage as blobs. The camera seems to default to the maximum resolution when using it in code so I wanted to set it to something smaller like 640 * 480 to make the size of the images smaller.

There is a nice code sample here of how to do it:

http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202951(v=vs.105).aspx

But when I placed this code in the OnNavigatedTo method of my xaml page I was getting an error. Seems the way to get this to work off the bat is to make use of the camera_Initialized event. So in OnNavigatedTo add:

camera = new PhotoCamera();
camera.Initialized += camera_Initialized;

and in the camera_Initialized event you can change the resolution:

Size res = camera.AvailableResolutions.ElementAt(0);
camera.Resolution = res;

Hope this saves someone some time…!

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *