Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Crop Images without degrading their quality (Using CGContextRef)

    • 0
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 605
    Comment on it

    Often the images cropped from other images in iPhone SDK are degraded in quality. This is because we take a snapshot of the original image (of the desired area). But the below mentioned code prevents from happening the above mentioned issue. The below mentioned code first upgrades quality of the image multiple times before cropping it (here the quality is upgraded to 4 times).

    UIGraphicsBeginImageContextWithOptions(cropRect.frame.size, view.opaque, 4.0);
    
        CGContextRef c = UIGraphicsGetCurrentContext();
    
        CGContextConcatCTM(c, CGAffineTransformMakeTranslation(-cropRect.frame.origin.x, -cropRect.frame.origin.y));
        [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    
        UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
    
        UIGraphicsEndImageContext();
    

 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: