How can i attached iphone image through mail in iphone

Posted by Pugal Devan on Stack Overflow See other posts from Stack Overflow or by Pugal Devan
Published on 2010-04-03T10:28:51Z Indexed on 2010/04/03 10:43 UTC
Read the original article Hit count: 364

Hi,

I am new to iphone development. I have created a button in the view. On clicking the button it loads the photolibrary from the Iphone. Now i want to attached the those selected image through mail. I donno how to attach the image in MFMailComposerView.

How can i achieve this,

Here my code is,

-(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];
    }

Please help me out.

Thanks.

© Stack Overflow or respective owner

Related posts about image

Related posts about Attach