我正在尝试从 UIImageView
获取 UIImage
的可见部分。 UIImageView
占据整个屏幕。将捏合手势添加到 UIImageView
。因此,用户可以平移/缩放 ImageView 。平移/缩放后,我只想裁剪 ImageView 的可见部分。我试过很多方法。但它返回了错误的图像部分。
提前致谢。
最佳答案
将 QuartzCore 框架包含到您的项目中并实现此方法以从 ImageView 中获取图像的可见部分: (注意:我的意思是你在你的项目中使用了 ARC)
#import <QuartzCore/QuartzCore.h>
- (UIImage*)imageFromImageView:(UIImageView*)imageView
{
UIGraphicsBeginImageContext(imageView.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextRotateCTM(context, 2*M_PI);
[imageView.layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
关于iphone - iOS 为 UIImageView 获取图像的可见部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11120814/