使用AspectFill裁剪并保存UIImageView的可见区域 [英] Crop and save visible region of UIImageView using AspectFill
本文介绍了使用AspectFill裁剪并保存UIImageView的可见区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个全屏UIImageView,其中的图像设置为AspectFill(全出血),在使用Aspect Fill内容模式时,如何仅保存图像的可见部分?
I have a fullscreen UIImageView with a image in it set to AspectFill (full bleed), how can I save only the visible portion of the image when its using the Aspect Fill content mode?
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);
这是我当前的代码,裁剪和保存工作,只是无法正确裁剪。有什么想法吗?
This is my current code, cropping and saving works, its just not cropping correctly. Any ideas?
推荐答案
尝试一下:
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();
这篇关于使用AspectFill裁剪并保存UIImageView的可见区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文