iphone - 截屏

标签 iphone objective-c ios screenshot

我正在尝试捕捉(屏幕截图) 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/

相关文章:

iphone - 以编程方式访问 iOS 中的地址簿?

iphone - NSInteger和int给出异常

ios - CFBundleIdentifier”,不存在

ios - 这个委托(delegate)属性是否被强引用?

ios - 应用内购买的混淆因不包括 "restore"按钮而被拒绝

iphone - 如何从我的 iPhone App 文档目录中选择所有图像

iphone - 如何在 Mail Composer 中附加图像?

html - 如何从 iOS Webview 登录网站?

ios - 我如何处理他内部的 CCScene 和 CCButton 的触摸

iphone - 在选项卡栏应用程序中使用导航 Controller 。