2011-05-17 65 views
1

來自這個神聖聖域的小夥子們,從一個不同的.XIB捕捉UIImageView

新問題!我需要從不同的.XIB獲取UIImageView。 讓我把它的代碼,以便得到它的簡單:

1)

-(UIImage *)grabScreenImage{ 

    //screen = IBOutlet for the UIImageView 

    UIGraphicsBeginImageContext(self.screen.frame.size); 
    [(CALayer *)self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    NSLog(@"PASSED BY THE PHOTO DUDES"); 
    return image; 

} 

2)

-(UIImage *)takeGraphScreenImage{ 

//shouldBeGraphViewController = IBOutlet for the other UIViewController 
//shouldBeGraph = IBOutLet for the UIImageView in the ShouldBeGraphViewController 

     UIGraphicsBeginImageContext(shouldBeGraphViewController.shouldBeTheGraph.frame.size); 
     [(CALayer *)shouldBeGraphViewController.shouldBeTheGraph.layer renderInContext:UIGraphicsGetCurrentContext()]; 
     UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
     UIGraphicsGetCurrentContext(); 
     return image; 
    } 

(1)工作得很好,我捕捉到的圖像,並通過將其發送到電子郵件但(2)不。

我剛剛複製並粘貼並更改了一些參數,以便可以被其他人使用,但它會給我帶來很多錯誤。

3) - (IBAction爲)Sendmail的{

MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc]init]; 

UIImage *curretScreen = [[self takeGrabScreenImage]retain]; 
UIImage *graphScreen = [[self takeGraphScreenImage]retain]; 

if ([MFMailComposeViewController canSendMail]){ 
    NSLog(@"ENTERED THE GOOD PART OF THE IF"); 
    mailComposer.mailComposeDelegate = self; 
    [mailComposer setSubject:@"MY SCREENSHOT TEST"]; 
    [mailComposer addAttachmentData:UIImagePNGRepresentation(curretScreen) mimeType:@"image/png" fileName:@"SCREENSHOT"]; 
    [mailComposer addAttachmentData:UIImagePNGRepresentation(graphScreen) mimeType:@"image/png" fileName:@"SCREENSHOT-02"]; 

    //NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    //NSString* documentsDirectory = [paths objectAtIndex:0]; 

    /*for (NSString *x in [self.photoLocations allKeys]){ 
     NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:x]; 
     UIImage *item = [UIImage imageWithContentsOfFile:fullPath]; 
     [mailComposer addAttachmentData:UIImagePNGRepresentation(item, 0.5) mimeType:@"image/jpeg" fileName: 
    }*/ 

} else { ... } 

[mailComposer setMessageBody:@"PUT YOUR MESSAGE HERE" isHTML:NO]; 
[self presentModalViewController:mailComposer animated:YES]; 
[mailComposer release]; 
[curretScreen release]; 

}

我只是需要採取截圖來自UIImageViews的(來自兩個UIViewControllers),並通過電子郵件發送,電子郵件的部分已經完成並採取第一個截圖,但採取第二個截圖沒有。給我誤差修改這樣的:

Mon May 16 21:02:46 FGringo EmailSending[1036] <Error>: CGContextSaveGState: invalid context 0x0 
Mon May 16 21:02:46 FGringo EmailSending[1036] <Error>: CGContextSetAlpha: invalid context 0x0 

幫幫我吧,求你了! (:

回答

0
- (void)imagePickerController:(UIImagePickerController *)picker 
didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    // Dismiss image picker modal. 
    [picker dismissModalViewControllerAnimated:YES]; 

    if ([MFMailComposeViewController canSendMail]) { 
     // Create a string with HTML formatting for the email body. 
     NSMutableString *emailBody = [[NSMutableString alloc] initWithString:@"<html><body>"]; 

     // Add some text to it. 
     [emailBody appendString:@"<p>Body text goes here.</p>"]; 

     // You could repeat here with more text or images, otherwise 
     // close the HTML formatting. 
     [emailBody appendString:@"</body></html>"]; 
     NSLog(@"%@", emailBody); 

     // Create the mail composer window. 
     MFMailComposeViewController *emailDialog = [[MFMailComposeViewController alloc] init]; 
     emailDialog.mailComposeDelegate = self; 

     // Image to insert. 
     UIImage *emailImage = [info objectForKey:UIImagePickerControllerOriginalImage]; 

     if (emailImage != nil) { 
      NSData *data = UIImagePNGRepresentation(emailImage); 
      [emailDialog addAttachmentData:data mimeType:@"image/png" fileName:@"filename_goes_here.png"]; 
     } 

     [emailDialog setSubject:@"Subject goes here."]; 
     [emailDialog setMessageBody:emailBody isHTML:YES]; 

     [self presentModalViewController:emailDialog animated:YES]; 
     [emailDialog release]; 
     [emailBody release]; 
    } 
} 
+0

因爲我已經有發送和附加代碼,但正如我解釋的問題是:我在一個視圖「主視圖」,我需要從「截圖」從這個「主視圖」和「Secundary視圖」,但「發送郵件」按鈕位於「主視圖」上。 – Felipe 2011-05-17 17:31:51