Issue with UIImagePickerControllerEditedImage

前端 未结 4 1802
野的像风
野的像风 2021-01-01 02:32

I need edit my Images before they import to the app but after editing the image reduces some quality how can avoid this ?

- (void) imagePickerController:(UI         


        
4条回答
  •  醉梦人生
    2021-01-01 02:39

    You can crop UIImagePickerControllerOriginalImage manually by using the value provided via UIImagePickerControllerCropRect.

    Untested quick and dirty example:

    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);
    
        // …
    }    
    

提交回复
热议问题