Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • UIImage Cropping in Objc

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.02k
    Comment on it

    Some times we click picture from ios camera but it does not return us the same image as appears inside the camera frame. Use below function to get an image of exact size which was visible through camera.

    Follow these Steps:-

    Step 1. First of all set the captured image to an UIImageView.

    Step 2. Pass that camera uiview to below function so that we can get visible frame of opened camera view.

    Step 3. Also pass the UIImage (captured photo) as a param to below function.

    -(UIImage*)cutEdge:(UIView*)cameraView photo:(UIImage*)photo{
        UIImageView *imgTemp = [[UIImageView alloc]initWithFrame:self.view.frame];
        [imgTemp setImage:photo];
        CGRect frame = cropView.frame;
        UIGraphicsBeginImageContextWithOptions(frame.size, YES, 4.0);
        CGContextRef c = UIGraphicsGetCurrentContext();
        CGContextConcatCTM(c, CGAffineTransformMakeTranslation(-frame.origin.x, -frame.origin.y));
        [imgTemp.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return img;
    }

    This Function will return you an image which was appearing through the camera view. Happy Coding!!!

 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: