我有一个全屏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);
这是我目前的代码,裁剪和保存工作,它只是没有正确裁剪。有什么想法吗?
答案 0 :(得分:1)
试试这个:
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));
// save ...
CGImageRelease(image);
UIGraphicsEndImageContext();