屏幕区域的选择
我正在尝试制作应用内屏幕截图,其中包含以下代码。
如何选择截图的区域?例如,我想摆脱 UInavigation 栏和底部选项卡栏。我应该添加什么代码?
UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * imageData = UIImageJPEGRepresentation(image, 1.0);
if ( [MFMailComposeViewController canSendMail] ) {
MFMailComposeViewController * mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[mailComposer addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"attachment.jpg"];
I am trying to make a in-app screenshot which I have the following codes.
How can to select the area for the screenshot? e.g. I want to get rid of the UInavigation bar and the bottom tabbar. What code should I add?
UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * imageData = UIImageJPEGRepresentation(image, 1.0);
if ( [MFMailComposeViewController canSendMail] ) {
MFMailComposeViewController * mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[mailComposer addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"attachment.jpg"];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以识别该区域的
矩形
并裁剪图像的该部分以获得您需要的图像。如果您手动使用导航栏和/或选项卡栏,请相应地替换
self.navigationController.navigationBar
和self.tabBarController.tabBar
。You can identify the
rect
of the region and crop that part of the image to get the image you need.If you are manually using a navigation bar and/or tab bar then replace the
self.navigationController.navigationBar
andself.tabBarController.tabBar
appropriately.