【发布时间】:2014-05-15 09:20:52
【问题描述】:
我想将[self screenshot]; 作为附件添加到我的邮件功能中。如何在不将图像保存到照片库的情况下执行此操作?这是我在 ViewController.m 中的代码:
截图功能:
- (UIImage *)screenshot
{
UIImage *backgroundImage = [UIImage imageNamed:@"iphoneframe.png"];
UIGraphicsBeginImageContext(backgroundImage.size);
[backgroundImage drawInRect:CGRectMake(0, 0, backgroundImage.size.width, backgroundImage.size.height)];
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
[screenshot drawInRect:CGRectMake(backgroundImage.size.width - screenshot.size.width, backgroundImage.size.height - screenshot.size.height, screenshot.size.width, screenshot.size.height)];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
电子邮件功能:
- (void)sendMail
{
if ([MFMailComposeViewController canSendMail]){
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:@"Mein Punktestand bei KlickMich"];
//Attachement Object
UIImage *myImage = [UIImage imageNamed:@"image.jpg"];
NSData *imageData = UIImagePNGRepresentation(myImage);
[mailer addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"image.jpg"];
NSString *messageBody = [NSString stringWithFormat:@"Hey, habe gerade ganze %i Punkte innerhalb von nur 15 Sekunden in der KlickMich App erreicht. Kannst du es besser?<br /><br />-> <a href='http://appstore.com/KlickMich'>appstore.com/KlickMich</a>",count];
[mailer setMessageBody:messageBody isHTML:YES];
[self presentViewController:mailer animated:YES completion:NULL];
}
[…]
你的忠实
罗宾
【问题讨论】:
-
您能否展示您已经尝试过但不起作用的方法并更详细地解释问题?您是否很难将创建的图像引用到 sendMail 方法中?等等。
标签: ios objective-c email screenshot