Ios 使用AspectFill裁剪并保存UIImageView的可见区域

Ios 使用AspectFill裁剪并保存UIImageView的可见区域,ios,objective-c,uiimageview,crop,Ios,Objective C,Uiimageview,Crop,我有一个全屏UIImageView,其中的图像设置为AspectFill(完全出血),当它使用Aspect Fill内容模式时,如何仅保存图像的可见部分 CGRect visibleRect; visibleRect.size= mImageView.frame.size; CGImageRef cropped_img = CGImageCreateWithImageInRect(mImageView.image.CGImage, visibleRect); UIImage *finalI

我有一个全屏UIImageView,其中的图像设置为AspectFill(完全出血),当它使用Aspect Fill内容模式时,如何仅保存图像的可见部分

CGRect visibleRect;   
visibleRect.size= mImageView.frame.size;
CGImageRef cropped_img = CGImageCreateWithImageInRect(mImageView.image.CGImage, visibleRect);
UIImage *finalImage = [[UIImage alloc]initWithCGImage:cropped_img];
UIImageWriteToSavedPhotosAlbum(finalImage, nil, nil, nil);
这是我当前的代码,裁剪和保存工作,只是裁剪不正确。有什么想法吗?

试试这个:

UIGraphicsBeginImageContext(mImageView.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGImageRef image = CGBitmapContextCreateImage(context);
width = CGImageGetWidth(image);
height = CGImageGetHeight(image);
CGImageRef cropped_img = CGImageCreateWithImageInRect(image, CGRectMake(0, 0, width, height));
//保存

CGImageRelease(image);
UIGraphicsEndImageContext();

我将UIImageView的属性设置为setClipsToBounds:YES和contentMode=UIViewContentModeScaleAspectFill。它不适用于我的imageview。