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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)