Efficient cropping
===

I have been struggling with cropping of the image. 
I am trying to crop to a CGRect(10,60,300,300).

My code is as follows:


    CGFloat hscale=image.size.width/320.0;
    CGRect fr=_overlayViewController.cropView.frame;
    CGRect scaledRect=CGRectMake(fr.origin.x*hscale, fr.origin.y*hscale, fr.size.width*hscale, fr.size.height*hscale);
    UIImage *imageCropped=[self cropImage:image rect:scaledRect];

and 

    -(UIImage *)cropImage:(UIImage *)image rect:(CGRect)rect{
    CIImage *img=[CIImage imageWithCGImage:[image CGImage]];
    CIImage *croppedImg=[img imageByCroppingToRect:rect];
    if (!_context) {
        _context = [CIContext contextWithOptions:nil];
    }
    CGImageRef imgref=[_context createCGImage:croppedImg fromRect:croppedImg.extent] ;
    
    UIImage *imgcropped=[UIImage imageWithCGImage:imgref scale:image.scale orientation:image.imageOrientation];
    CGImageRelease(imgref);
    img=nil;
    croppedImg=nil;
    return imgcropped;
}

I have a couple of issues.

I see that x & Y are reversed. and also I am getting memory warning. How can make this better?

Thanks in advance.