My application just sends me an empty png (although it is the right size at least). The view I’m telling it to draw the image from definitely has content. Here is the relevant code.
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"];
Can anyone spot any problems? Thanks.
You aren’t actually drawing the view onto the context. You will have to use
renderInContext:method ofCALayerso addQuartzCoreframework to your project and#import <QuartzCore/QuartzCore.h>.Do
before your
UIGraphicsGetImageFromCurrentImageContext()call.