在UIImagePickerControllerSourceTypeCamera之后立即调整图像大小

时间:2013-12-24 17:52:10

标签: ios iphone objective-c

我正在尝试执行我认为调整刚刚通过UIImagePickerControllerSourceTypeCamera拍摄的图像的简单任务。

拍摄照片后,我想立即缩小图片。我很好地保持纵横比并将其缩小到约25%。这是我拉取刚刚拍摄的图像(称为cameraImage)。

任何帮助都会很精彩!谢谢你们!

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

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

}

1 个答案:

答案 0 :(得分:2)

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;
}