ios - 截取 ImageView 的屏幕截图

标签 ios uiimageview screenshot

我有一个 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/

相关文章:

ios - 在 iOS 中使用图像(png、jpg)的最佳格式是什么?

android - 如何在最近的应用程序中使屏幕空白但允许屏幕截图

ios - 添加点/小数后 UITextField 搞砸了

ios - 使用 JSONModel (IOS) 在光盘上保存对象数组

ios - 带有 UIAlertAction swift 的增量标签栏角标(Badge)?

ios - UITableView "cellForRowAt: indexPath"偶尔在核心数据属性上调用 "init?(coder aDecoder: NSCoder)"

ios - 如何在 Objective-C 中获取 NSArray 中的当前位置

ios - XCode:IBOutlet 连接如何消失并仍然存在?

linux - 在 Linux 上,如何使用 POSIX shell 禁用鼠标一秒钟,而不是等待第二个并立即做一些工作?

android - 以编程方式为 Google map V2 截取屏幕截图