简体   繁体   中英

Immediately Resize Image after UIImagePickerControllerSourceTypeCamera

I am trying to perform what I think would be the simple task of resizing an image that was just taken via UIImagePickerControllerSourceTypeCamera.

After I take the picture, I would like to immediately scale it down. I am fine with maintaining the aspect ratio and scaling it down to about 25%. Here is where I pull the image that was just taken (called cameraImage).

Any help would be wonderful! Thank you all!

-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {

    cameraImage = [info objectForKey:UIImagePickerControllerOriginalImage];
    [[picker presentingViewController] dismissViewControllerAnimated:YES 
    completion:^{[self photoUpload];}];

}
UIImage *scaleDownImg = [ClassName imageWithImage: cameraImage scaledToSize:CGSizeMake(20, 20)];

+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
    //UIGraphicsBeginImageContext(newSize);
    // In next line, pass 0.0 to use the current device's pixel scaling factor (and thus account for Retina resolution).
    // Pass 1.0 to force exact pixel size.
    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();
    return newImage;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM