1

UIImagePickerController以下のデリゲートメソッド を使用してiPhoneから画像をキャプチャしました。

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

コードに誤りがあったことをお詫びします。

4

1 に答える 1

0

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

メールボタンを次のように宣言したと仮定すると、

UIButton *emailbutton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //or any other way

このメソッドをボタン ターゲットとしてその行の直後に追加します。

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

デリゲートで設定したemailbutton画像をタップすると、添付ファイルとして送信されます。self.myimageview.imageUIImagePickerController

于 2012-11-01T22:48:37.623 に答える