I am working with image. I have a cropping functionality which only allows cropping in 2:1 ratio (width:height ratio). So if the image is in other ratio the user can zoom out and fit the image inside the cropping window but I want to add black area to the side of the image so that the resultant image is always in 2:1 ratio.
Please see the screenshot
This is the code I am using:
#Check the ratio
#Get the resultant size ie. resultant width and height
//crashes here
UIGraphicsBeginImageContextWithOptions(CGSizeMake(newImageWidth, newImageHeight), YES, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();
UIGraphicsPushContext(context);
CGPoint origin = CGPointMake((newImageWidth - image.size.width) / 2.0f, (newImageHeight - image.size.height) / 2.0f);
[image drawAtPoint:origin];
UIGraphicsPopContext();
This code is working fine in iOS app but when I use this code in app extension it crashes because of memory leak. It crashes in UIGraphicsBeginImageContextWithOptions.
Is there any other way to add black area to the image without memory leak?
Hope you understand the problem.
Thanks in advance.