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.41k
    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]
                           forKey:@"inputScale"];
            [scaleFilter setValue:[NSNumber numberWithFloat:1.0]
                           forKey:@"inputAspectRatio"];
            [scaleFilter setValue: image
                           forKey:@"inputImage"];
    
            UIImage *outputImage = [scaleFilter valueForKey:@"outputImage"];
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
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: