LPPloveROU 2012-11-02 02:29 采纳率: 50%
浏览 2239

点击按钮实现email附加捕捉图片

iphone应用中,捕捉图片使用UIImagePickerController:

    - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    self.myImageView.image = image;  
    //    [self performSelector:@selector(emailButtonPressed:) withObject:image afterDelay:1.0];
     [self dismissModalViewControllerAnimated:YES];  
}

其中emailButtonPressed方法由self调用。我希望可以按钮动作调用这个,因此写了下面的代码emailButtonPressed

- (void)emailButtonPressed:(UIImage *)image
{  
        MFMailComposeViewController *mailview=[[MFMailComposeViewController alloc]init];      mailview.navigationBar.tintColor=[UIColor colorWithRed:55/255.0 green:190/255.0 blue:55/255.0 alpha:1];  
        mailview.mailComposeDelegate=self;  
        // NSMutableString *subject=[NSMutableString stringWithFormat:@"%@",@"Testing"];  
        [mailview setSubject:@"Picture from my iPhone!"];  
        //   NSString *email_new=@"";  
        [mailview setMessageBody:@"Description" isHTML:NO];  

        NSData *imageData = UIImagePNGRepresentation(image);  

        [mailview addAttachmentData:imageData mimeType:@"image/png" fileName:@"ImageName"];  
        [self presentModalViewController:mailview animated:YES];  
}

请多指教,谢谢~

  • 写回答

1条回答

  • Mr_me 2012-11-02 06:32
    关注

    修改emailButtonPressed 方法:

    • (void)emailButtonPressed //removed the param
      {

      UIImage *image = self.myimageview.image; //or set some other param as image = self.image; whichever you set in picker delegate method
      MFMailComposeViewController *mailview=[[MFMailComposeViewController alloc]init]; mailview.navigationBar.tintColor=[UIColor colorWithRed:55/255.0 green:190/255.0 blue:55/255.0 alpha:1];

      mailview.mailComposeDelegate=self;

      // NSMutableString *subject=[NSMutableString stringWithFormat:@"%@",@"Testing"];

      [mailview setSubject:@"Picture from my iPhone!"];

      // NSString *email_new=@"";

      [mailview setMessageBody:@"Description" isHTML:NO];

      NSData *imageData = UIImagePNGRepresentation(image);  
      
      [mailview addAttachmentData:imageData mimeType:@"image/png" fileName:@"ImageName"];  
      [self presentModalViewController:mailview animated:YES];  
      

      }
      然后:

      • (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; self.myImageView.image = image; //instead of this, you can create an @property for image in .h file and assign to that also here. [self dismissModalViewControllerAnimated:YES];
        }

    如果已经声明了emailbutton:

    UIButton *emailbutton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    

    然后添加:

    [emailbutton addTarget:self action:@selector(emailButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog