2012-11-16 86 views

回答

6

將其轉換爲圖像並將該圖像作爲附件發送。

+ (UIImage *) imageWithView:(UIView *)view 
{ 
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, [[UIScreen mainScreen] scale]); 
    [view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return img; 
} 

-(void)displayComposerSheet 
{ 
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
    picker.mailComposeDelegate = self; 
    [picker setSubject:@"Check out this image!"]; 

    // Set up recipients 
    // NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 
    // NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil]; 
    // NSArray *bccRecipients = [NSArray arrayWithObject:@"[email protected]"]; 

    // [picker setToRecipients:toRecipients]; 
    // [picker setCcRecipients:ccRecipients]; 
    // [picker setBccRecipients:bccRecipients]; 

    // Attach an image to the email 
    UIImage *coolImage = ...; 
    NSData *myData = UIImagePNGRepresentation(coolImage); 
    [picker addAttachmentData:myData mimeType:@"image/png" fileName:@"coolImage.png"]; 

    // Fill out the email body text 
    NSString *emailBody = @"My cool image is attached"; 
    [picker setMessageBody:emailBody isHTML:NO]; 
    [self presentModalViewController:picker animated:YES]; 

    [picker release]; 
} 
+0

非常有用:)感謝 –

+0

還有一個提示:總是做搜索和研究這是一個電腦程序員是關於,99%的東西,你會發現。更多你重新/搜索更多,你會學習。經過1天的搜索後...在這裏發帖:) –

+0

@AnoopVaidya +1對於它...... – Kamarshad

3

你可以做到這一點只有當你將其轉換爲圖像。

轉換爲圖像

,您必須首先在鏈接QuartzCore框架,也#import <QuartzCore/QuartzCore.h>

下一頁插入到代碼:

UIGraphicsBeginImageContext(myView.bounds.size); 
[myView.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

來源:http://iphonedevelopment.blogspot.com/2008/10/getting-contents-of-uiview-as-uiimage.html

發送電子郵件地址

您可以使用MFMailComposeViewController類,因此您不必離開您的應用程序。本教程幫助我:

http://iphonedevsdk.com/forum/tutorial-discussion/43633-quick-tutorial-how-add-mfmailcomposeviewcontroller.html

要添加圖像,你可以使用同一個類的方法:addAttachmentData:mimeType:fileName:帶三個參數。檢查蘋果文件以獲取更多信息。

+0

謝謝。我正在閱讀有關某些書籍的郵件,而我沒有找到關於圖片的信息。 –

+0

檢查這些文檔:http://developer.apple.com/library/ios/#documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html – achi

相關問題