How to Desaturate a UIImage

I recently needed to figure out how to take a photo with the camera, and then desaturate it. I needed to control the level of desaturation, ranging from completely greyscale, all the way up to the original image. This turned out to be trickier than expected, but in...