Hi Guys,
I have this working fine to rotate an image at arbitrary angles,
except when it is called enough times, I get low memory warnings,
followed by App crash.
THe function originally had a release or autorelease statement in it
that had to be removed for an ARC project.
Called with this:
Any ideas as to why this is happening?
As I said, it does work for a while to rotate an image a few times.
I keep changing the angle of rotation, but am only writing the result back to
rotImage, not creating a bunch of new image objects.
Cheers, Art.
I have this working fine to rotate an image at arbitrary angles,
except when it is called enough times, I get low memory warnings,
followed by App crash.
THe function originally had a release or autorelease statement in it
that had to be removed for an ARC project.
Code:
- (CGImageRef)CGImageRotatedByAngle:(CGImageRef)imgRef angle:(CGFloat)angle
{
CGFloat angleInRadians = angle * (M_PI / 180);
CGFloat width = CGImageGetWidth(imgRef);
CGFloat height = CGImageGetHeight(imgRef);
CGRect imgRect = CGRectMake(0, 0, width, height);
CGAffineTransform transform = CGAffineTransformMakeRotation(angleInRadians);
CGRect rotatedRect = CGRectApplyAffineTransform(imgRect, transform);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef bmContext = CGBitmapContextCreate(NULL,
rotatedRect.size.width,
rotatedRect.size.height,
8,
0,
colorSpace,
kCGImageAlphaPremultipliedFirst);
CGContextSetAllowsAntialiasing(bmContext, YES);
CGContextSetShouldAntialias(bmContext, YES);
CGContextSetInterpolationQuality(bmContext, kCGInterpolationHigh);
CGColorSpaceRelease(colorSpace);
CGContextTranslateCTM(bmContext,
+(rotatedRect.size.width/2),
+(rotatedRect.size.height/2));
CGContextRotateCTM(bmContext, angleInRadians);
CGContextTranslateCTM(bmContext,
-(rotatedRect.size.width/2),
-(rotatedRect.size.height/2));
CGContextDrawImage(bmContext, CGRectMake(0, 0,
rotatedRect.size.width,
rotatedRect.size.height),
imgRef);
rotatedImage = CGBitmapContextCreateImage(bmContext);
CFRelease(bmContext);
return rotatedImage;
}
Called with this:
Code:
CGImageRef imageRef = [self CGImageRotatedByAngle:[oldImage CGImage] angle:rotation];
rotImage = [UIImage imageWithCGImage: imageRef];
Any ideas as to why this is happening?
As I said, it does work for a while to rotate an image a few times.
I keep changing the angle of rotation, but am only writing the result back to
rotImage, not creating a bunch of new image objects.
Cheers, Art.