Scaling and Rotating an image in MonoTouch

I've been messing with this code for a couple of days, and finally got it working over the weekend.

The problem was, when using an image taken on the iPhone, the image is stored the same way each time (landscape, I think), but with the rotation stored in the EXIF data. If you want a proper JPEG - or even to scale the original - you have to do the rotation yourself. Which is kinda nasty.

I found various bits of code around which should do this, including a MonoTouch port, but in general, they didn't work. I think the problem was all about the CoreGraphics co-ordinates vrs screen or UIKit co-ordinates.

So, here's my code - which I ported from someone else's, so I can't really claim it. But I hope it's of help to someone!