Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Cropping image without degrading their quality (Using CIFilter's CICrop filter)

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.42k
    Comment on it

    The below mentioned code uses CIImage library's CICrop filter to crop the desired area from UIImage. The follwing code deoesn't deals with snapshot as CGContextRef rather crops the original image along with maintaining its quality and aspect ratio.

            CGImageRef imageRef = [[UIImage imageNamed@"your_image"] CGImage];
            CIImage *image = [CIImage imageWithCGImage:imageRef];
            CIFilter *scaleFilter = [CIFilter filterWithName:@"CILanczosScaleTransform"];
            int originalHeight=[image extent].size.height;
            int originalWidth=[image extent].size.width;
            float yScale=screenHeight / (float)originalHeight;
            float xScale=screenWidth / (float)originalWidth;
            float scale=fminf(yScale, xScale);
            [scaleFilter setValue:[NSNumber numberWithFloat:scale]
            [scaleFilter setValue:[NSNumber numberWithFloat:1.0]
            [scaleFilter setValue: image
            UIImage *outputImage = [scaleFilter valueForKey:@"outputImage"];

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: