我的应用程序只给我一个空的png(虽然它至少是正确的大小)。我告诉它从中绘制图像的视图肯定有内容。这是相关的代码。
UIGraphicsBeginImageContext(graph_window_view_controller.view.bounds.size);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(image);
...
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:[@"******** " stringByAppendingString:theTime]];
[mailViewController setMessageBody:@"*********" isHTML:NO];
[mailViewController setToRecipients:[NSArray arrayWithObject:str]];
[mailViewController addAttachmentData:data mimeType:@"image/png" fileName:@"chart_image.png"];
有人能发现任何问题吗?感谢。
答案 0 :(得分:0)
您实际上并未将视图绘制到上下文中。您必须使用renderInContext:
CALayer
方法,因此请将QuartzCore
框架添加到您的项目中,并#import <QuartzCore/QuartzCore.h>
。
待办事项
[graph_window_view_controller.view.layer renderInContext:UIGraphicsGetCurrentContext()];
在UIGraphicsGetImageFromCurrentImageContext()
来电之前。