[英]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. 我正在尝试执行我认为调整刚刚通过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%.
我很好地保持纵横比并将其缩小到约25%。 Here is where I pull the image that was just taken (called cameraImage).
这是我拉取刚拍摄的图像(称为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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.