我正在尝试捕捉(屏幕截图) View 。为此,我使用下面显示的一段代码将其作为 PNG 图像保存到我的文档目录中。
UIGraphicsBeginImageContextWithOptions(highlightViewController.fhView.centerView.frame.size, YES, 1.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"1.png"];
NSData *imageData = UIImagePNGRepresentation(screenshot);
[imageData writeToFile:appFile atomically:YES];
UIGraphicsEndImageContext();
问题:我可以捕捉部分 View 吗?因为在上面的代码中我不能改变原点(框架)。如果有人有其他方法来捕捉 View 的特定部分,请分享。
最佳答案
您可以裁剪图像: http://iosdevelopertips.com/graphics/how-to-crop-an-image.html
CGRect rect = CGRectMake(0,0,10,10);
CGImageRef imageRef = CGImageCreateWithImageInRect([screenshot CGImage], rect);
UIImage *croppedScreenshot = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
关于iphone - 截屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7429854/