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 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥20 Python安装cvxpy库出问题
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题