【发布时间】:2011-05-17 00:03:42
【问题描述】:
来自这个神圣避难所的家伙,
新问题!我需要从不同的.XIB 中获取 UIImageView。 让我把它放在代码中,这样会更简单:
1)
-(UIImage *)grabScreenImage{
//screen = IBOutlet for the UIImageView
UIGraphicsBeginImageContext(self.screen.frame.size);
[(CALayer *)self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSLog(@"PASSED BY THE PHOTO DUDES");
return image;
}
2)
-(UIImage *)takeGraphScreenImage{
//shouldBeGraphViewController = IBOutlet for the other UIViewController
//shouldBeGraph = IBOutLet for the UIImageView in the ShouldBeGraphViewController
UIGraphicsBeginImageContext(shouldBeGraphViewController.shouldBeTheGraph.frame.size);
[(CALayer *)shouldBeGraphViewController.shouldBeTheGraph.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsGetCurrentContext();
return image;
}
(1) 工作正常,我捕获图像并通过电子邮件发送,但 (2) 没有。
我只是复制并粘贴并更改了一些参数,以便其他人可以使用它,但它给了我很多错误。
3) -(IBAction)sendMail{
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc]init];
UIImage *curretScreen = [[self takeGrabScreenImage]retain];
UIImage *graphScreen = [[self takeGraphScreenImage]retain];
if ([MFMailComposeViewController canSendMail]){
NSLog(@"ENTERED THE GOOD PART OF THE IF");
mailComposer.mailComposeDelegate = self;
[mailComposer setSubject:@"MY SCREENSHOT TEST"];
[mailComposer addAttachmentData:UIImagePNGRepresentation(curretScreen) mimeType:@"image/png" fileName:@"SCREENSHOT"];
[mailComposer addAttachmentData:UIImagePNGRepresentation(graphScreen) mimeType:@"image/png" fileName:@"SCREENSHOT-02"];
//NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//NSString* documentsDirectory = [paths objectAtIndex:0];
/*for (NSString *x in [self.photoLocations allKeys]){
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:x];
UIImage *item = [UIImage imageWithContentsOfFile:fullPath];
[mailComposer addAttachmentData:UIImagePNGRepresentation(item, 0.5) mimeType:@"image/jpeg" fileName:
}*/
} else { ... }
[mailComposer setMessageBody:@"PUT YOUR MESSAGE HERE" isHTML:NO];
[self presentModalViewController:mailComposer animated:YES];
[mailComposer release];
[curretScreen release];
}
我只需要从两个 UIImageViews(来自两个 UIViewControllers)截取屏幕截图并通过电子邮件发送,电子邮件部分已完成并截取第一个屏幕截图,但不截取第二个屏幕截图。给我这样的错误:
Mon May 16 21:02:46 FGringo EmailSending[1036] <Error>: CGContextSaveGState: invalid context 0x0
Mon May 16 21:02:46 FGringo EmailSending[1036] <Error>: CGContextSetAlpha: invalid context 0x0
请帮帮我! (:
【问题讨论】:
标签: iphone objective-c xcode xcode4