Objective-C Image crop function

mg.1040mg.1040 USMember
edited March 2014 in Xamarin.iOS

Banging my head trying to port a Objective-C image crop function to C#:

UIImage* cropImage(UIImage* srcImage, CGRect* rect)
{
CGImageRef cr = CGImageCreateWithImageInRect([srcImage CGImage], rect);
UIImage
cropped = [[[UIImage alloc] initWithCGImage:cr] autorelease];
CGImageRelease(cr);
return cropped;
}

What would the C# equivalent of these two lines be?

UIImage* cropped = [[[UIImage alloc] initWithCGImage:cr] autorelease];

CGImageRelease(cr);

Posts

  • Sreeraj.0276Sreeraj.0276 USMember ✭✭

    This is a compact and clean solution. But when I load the UIImage returned from cropImage, it appears to rotated by 90 degrees.
    I think this has been handled in the solution here

  • Thanks Colby!

Sign In or Register to comment.