我有一个 ImageView
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
我想截图。我的代码占据了整个屏幕。我已经查看了此处的其他答案,但仍然无法解决,因为我不想指定尺寸,我只需要整个 ImageView 作为屏幕截图。
- (UIImage*)captureView:(UIView *)view
{
CGRect rect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
最佳答案
替换行
CGRect rect = [[UIScreen mainScreen] bounds];
与
CGRect rect = view.bounds;
希望这会如您所愿。
关于ios - 截取 ImageView 的屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36018079/