开发者

Problem taking a UIImage of a view and attaching it to an email

开发者 https://www.devze.com 2023-03-21 08:28 出处:网络
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.

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:@"*********" i开发者_如何学编程sHTML: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 of CALayer so add QuartzCore framework to your project and #import <QuartzCore/QuartzCore.h>.

Do

[graph_window_view_controller.view.layer renderInContext:UIGraphicsGetCurrentContext()];

before your UIGraphicsGetImageFromCurrentImageContext() call.

0

精彩评论

暂无评论...
验证码 换一张
取 消