我有一个带按钮的视图控制器,当按下它时,它会截取整个屏幕的截图:
@implementation ViewController
-(IBAction)Screenshot {
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshotimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(screenshotimage, nil, nil, nil);
}
@end问题:我应该如何获取屏幕特定部分的屏幕截图?
也就是说,我需要屏幕截图是一个特定的矩形,而不是整个屏幕
有什么建议吗?
谢谢
发布于 2014-05-12 04:35:59
您有两个选择:
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];,而不是[otherview.layer renderInContext:UIGraphicsGetCurrentContext()];,其中otherview是你预先放置的一个视图,它包含了你想要截图的屏幕的所有部分作为子视图。发布于 2014-05-12 04:35:22
使用所需的矩形大小创建图像上下文,并在调用renderInContext:之前使用CGContextTranslateCTM在坐标系原点周围“移动”以将屏幕的特定部分绘制到该上下文中。
https://stackoverflow.com/questions/23597494
复制相似问题