【发布时间】:2013-07-20 04:54:14
【问题描述】:
我正在尝试将视图捕获为图像,然后通过邮件附加该图像,但问题是捕获视图后图像周围出现白色边框! ,这个问题只发生在 iPhone 5 设备上!这是我的代码:
分享.m
- (void)mailAttachmentWithImage:(UIView*)view openInView:(UIViewController*)viewCont {
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
UIView* captureView = view;
captureView.backgroundColor = [UIColor clearColor];
/* Capture the screen shoot at native resolution */
UIGraphicsBeginImageContextWithOptions(captureView.bounds.size, NO, 0.0);
[captureView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
/* Render the screen shot at custom resolution */
CGRect cropRect = CGRectMake(0 ,0 ,1024 ,1024);
UIGraphicsBeginImageContextWithOptions(cropRect.size, NO, 1.0f);
[screenshot drawInRect:cropRect];
UIImage * customScreenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *myData = UIImagePNGRepresentation(customScreenShot);
[controller addAttachmentData:myData mimeType:@"image/png" fileName:@"Image"];
[viewCont presentViewController:controller animated:YES completion:nil];
}
ViewController.m
然后捕获视图:
- (IBAction)mail:(id)sender {
[shareIt mailAttachmentWithImage:_captureView openInView:self];
}
【问题讨论】:
-
请提供有关您正在捕获的视图的更多信息。该视图预捕获的屏幕截图?
-
@AlfieHanssen 查看我编辑的问题,它只发生在 iPhone 5 上!!!真的很奇怪!!!
-
你帖子中的图片(那个人的照片)是你截取的截图吗?还是您从中捕获的视图?从表面上看,我猜您正在捕获一个比图像本身更大的边界框,从而产生白色边框。如果它只是发生在 iPhone 5 上,是否意味着它没有发生在其他设备上?
-
@AlfieHanssen 不!它捕获的图像!这就是发生的事情!图像周围出现白色边框
-
也许值得一试... [customScreenShot.layer setBorderColor: [[UIColor clearColor] CGColor]]; - 这会将图层的边框颜色设置为清除。
标签: iphone ios objective-c