I'm using this code to resize an image taken with the camera. I reduce it proportionally to a thumbnail, but then I'd like to crop it into a 60x60 square format. I tried incorporating:
CGImageRef imageRef = CGImageCreateWithImageInRect(CGImage, rect);
but I didn't manage to get it working correctly.How would I do this using Core Graphics?
- (UIImage *) resizeCapturedImage:(UIImage *) img toWidth:(float) w{
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGContextRef ctx = CGBitmapContextCreate(NULL,w,w, 8, 0, colorspace,kCGImageAlphaPremultipliedFirst);
CGContextDrawImage(ctx, CGRectMake(0, 0, w,img.size.width*w/img.size.height), img.CGImage);
CGImageRef thumb = CGBitmapContextCreateImage(ctx);
UIImage *final = [UIImage imageWithCGImage:thumb scale:1.0 orientation:UIImageOrientationRight];
return final;
}