0
我是iphone開發新手。我在視圖中創建了一個按鈕。點擊按鈕時,它會從iPhone中加載光子庫。現在我想通過郵件附加這些選定的圖像。我不知道如何在MFMailComposerView中附加圖像。我怎樣才能通過iPhone中的郵件附加iphone圖像
我怎樣才能做到這一點,
這裏我的代碼,
-(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];
}
請幫助我。
謝謝。
一眼就看不出代碼有什麼問題(我的應用程序使用UIImagePNGRepresenation的方式與您的相同)。究竟發生了什麼問題? – 2010-04-03 10:42:57
如何將圖像從didFinishPickingImage方法發送到右鍵方法。以便我可以將圖像傳遞給郵件。 – Pugal 2010-04-03 11:03:58