我需要在将图像导入应用程序之前对其进行编辑,但编辑图像后会降低一些质量,如何避免这种情况?
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self dismissModalViewControllerAnimated:YES];
imgEdited.image = [info objectForKey:UIImagePickerControllerEditedImage];
}
您可以裁剪UIImagePickerControllerOriginalImage
手动使用通过提供的值UIImagePickerControllerCropRect
.
未经测试的快速和肮脏的例子:
static UIImage *my_croppedImage(UIImage *image, CGRect cropRect)
{
UIGraphicsBeginImageContext(cropRect.size);
[image drawAtPoint:CGPointMake(-cropRect.origin.x, -cropRect.origin.y)];
UIImage *cropped = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return cropped;
}
- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// …
UIImage *originalImage = info[UIImagePickerControllerOriginalImage];
CGRect cropRect = [info[UIImagePickerControllerCropRect] CGRectValue];
UIImage *croppedImage = my_croppedImage(originalImage, cropRect);
// …
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)