Try something like this, it is not EXACTLY the same questions, but a slight change to this algorithm should work for you!!!
Draw border just inside non-transparent portion of image
It does not give exact code for any platform, but gives the mathematical geometry and generic looping algorithm for how to accomplish such a task.
Within iOS you will need to perform the new image creation (and indeed pixel copy over) using CoreGraphics.
Things you will HAVE to look out for. The screen resolution to actual image resolution. If the image resolution is different, then when you perform you math to calculate the crop zone, that crop zone may grow or shrink when translating from the screen to the actual backing image being displayed.