Lessons Learnt Using the Windows Phone Camera API : Part 2

A few months ago I wrote a post about some of the stuff I learnt working with the Windows Phone camera API for Foundbite, here’s some more I’ve learnt since….

Disable Camera Buttons

Initiating a photo capture can sometimes take a bit of time, especially if you’re focusing as well, and I found even if you give the user some loading feedback it’s quite likely they might try to press the button more than once. If they do this the phone will try to initiate another camera capture which will most likely throw an InvalidOperationException. In Foundbite, after suffering from many of these exceptions, I’m disabling the on screen button and the physical camera button when the capturing process is occurring.

Dispose the Camera

You may have noticed that if you don’t dispose an instance of the PhotoCaptureDevice whenever you leave the camera page it’ll cause a whole host of problems, including giving a nasty bug where the camera feed goes green- often needing a phone restart to right itself.

In the OnNavigatedTo event on the camera page I declare a new instance of the camera and in the OnNavigatedFrom I .Dispose() the PhotoCaptureDevice which has stopped this from occurring completely.

Don’t Assume All Phones Have the Same Resolutions

It’s best to assume that every phone has different resolutions available to avoid any unexpected problems when setting the resolution. I was initialising the camera in Foundbite using the 640 x 480 resolution which I though every phone would have as the minimum. However, it seems the new Nokia Lumia 1020 doesn’t have this low resolution so was causing a crash for that particular device.

I have an idea of what kind of size image I want so I just use this fairly schoolboy method to select the closest available resolution using the widths available and the desired width:

public static int GetNearestSizeIndex(List<int> widths, int wantedSize)
int distanceAway = int.MaxValue;
int index = 0;
for (int i = 0; i < widths.Count; i++)
int distance = Math.Abs(widths[i] – wantedSize);
if (distance < distanceAway)
distanceAway = distance;
index = i;
return index;

As I said, pretty basic but in Foundbite I’ve had to limit the size of images to improve image size and upload speed, so this is helpful for selecting the best resolution.

Focus Illumination Mode

The FocusIlluminationMode is the small flash you sometimes see when focusing the camera. I wasn’t aware you could even control this to start off with but to stop annoying your users its best to give them an option to turn this off if they so wish (or keep it on all the time).

Make sure you check that the phone has a flash before allowing the user to manipulate the illumination mode as a Nokia Lumia 520 only has one FocusilluminationMode (off) as it has no flash.

if(camera.IsFlashAvailable()) camera.SetIlluminationMode(Settings.FocusMode.Value);

Which uses these two methods:

public void SetIlluminationMode(FocusIlluminationMode mode)
Device.SetProperty(KnownCameraPhotoProperties.FocusIlluminationMode, mode);

public bool IsFlashAvailable()
return (GetAvailableFlashStates().ToList().Count() > 1);

For more help using the camera I found this Camera Explorer sample from Nokia amazingly useful……


Response time difference between Windows Azure extra small and small instances

This was originally posted on my old blog.

When Foundbite was in its very early stages I was using the Windows Azure Extra Small instance to host the API and with a very small number of beta testers the response time was more than fine, though did fluctuate a lot.

As the beta expanded and because I get a free allowance for Windows Azure through BizSpark, I decided to move my web role up to a Small Instance. Unlike the Extra Small, the Small instance is not shared with others and I was curious to see the response time gains that could be had. Turns out, they are quite significant:

Although I realise this isn’t a completely fair test as the number of requests and type of requests vary, it’s quite apparent that the response time dropped significantly. I hadn’t expected such a clear distinction.

You can see the difference in size between instances here, I have no idea how much an A7 costs but wow that’s a lot of power!

If you need help choosing an instance size, this article is also really useful.

The above graph was made using New Relic Performance Monitoring which you can get for free using your Azure subscription.