2010-04-03 3 views
0

저는 아이폰 개발을 처음 사용합니다. 보기에 단추를 만들었습니다. 버튼을 클릭하면 아이폰에서 사진 라이브러리를 불러옵니다. 이제 저는 선택한 이미지를 우편으로 첨부하고 싶습니다. MFMailComposerView에 이미지를 첨부하는 방법을 모르겠다.어떻게 iphone 이미지를 아이폰에 메일로 첨부 할 수 있습니까?

내가 이것을 달성 할 수있는 방법

, 여기

내 코드는,

-(IBAction) Pictures:(id)sender 
{ 
    self.imgpicker = [[UIImagePickerController alloc] init]; 
    self.imgpicker.delegate = self; 
    self.imgpicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    [self presentModalViewController:self.imgpicker animated:YES]; 
} 

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img1 editingInfo:(NSDictionary *)editInfo { 
    [[picker parentViewController] dismissModalViewControllerAnimated:NO]; 
    UIView *view = [[UIView alloc] init]; (This view for displaying the images) 
    imageview = [[UIImageView alloc] initWithImage:img1]; 
    [imageview setFrame:CGRectMake(0, 0, 320, 420)]; 
    [self.view addSubview:imageview]; 
    [view release]; 

    UIBarButtonItem *rightbutton = [[UIBarButtonItem alloc] initWithTitle:@"Email" style:UIBarButtonItemStyleBordered target:self action:@selector(rightbutton)]; 
    self.navigationItem.rightBarButtonItem = rightbutton; 
    [rightbutton release]; 

    } 

    -(void) rightbutton 
    { 
     [self emailImage:(UIImage *)image];(how to pass the image to mail view) 
    } 

    - (void)emailImage:(UIImage *)image 
    { 
     picker = [[MFMailComposeViewController alloc] init]; 
     picker.mailComposeDelegate = self; 
     [picker setToRecipients:[NSArray arrayWithObjects:@"[email protected]",nil]]; 
     NSData *data = UIImagePNGRepresentation(image); 
     [picker addAttachmentData:data mimeType:@"image/png" fileName:@"iPod Library Image"]; 
     [self presentModalViewController:picker animated:YES]; 
     [picker release]; 
    } 

저를 도와주세요.

감사합니다.

+1

한눈에 코드에 문제가없는 것을 볼 수 있습니다 (동일한 방법으로 UIImagePNGRepresenation을 사용하는 앱이 있습니다). 정확히 무엇이 잘못 될까요? –

+0

didFinishPickingImage 메서드의 이미지를 right button 메서드에 보내는 방법. 그래서 나는 이미지를 우편으로 보낼 수있다. – Pugal

답변

1

컨트롤러 클래스 (imageThatWasPicked 등)에 UIImage 인스턴스 변수를 설정 한 다음 -imagePickerController:didFinishPickingImage:editingInfo:에서 이미지를 가져올 때 해당 인스턴스 변수를 설정해야합니다. 그런 다음 -emailImage:을 호출 할 때이 인스턴스 변수를 참조 할 수 있습니다.

참고로 imageView이 유출되고 있으며 이미지 선택 도구 대리인 방법으로 view으로 무엇을하려고하는지 잘 모릅니다. 당신은 아마 view을 할당하고 풀어 놓는 코드를 제거 할 수 있습니다.

관련 문제