I’m trying to generate a scaled version of a UIView on a UIImage.
The code I have so far creates the UIImage and then scales it but I actually need to scale it first and then generate the UIImage for performance.
Here is the code:
UIGraphicsBeginImageContext([aView bounds].size);
[[aView layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIGraphicsBeginImageContext(aSize);
[image drawInRect:CGRectMake(0, 0, aSize.width, aSize.height)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
The idea is to have the first block of code create the Image Context with the scaled size and have aView rendered in that same context also scaled. The second block shouldn’t be necessary.
The solution was to create the Image Context with
UIGraphicsBeginImageContextWithOptions(size, isOpaque, scale);