【发布时间】:2013-07-04 19:04:44
【问题描述】:
我为拍摄照片创建了自定义相册。我在我的应用程序中调用了这张专辑。单击按钮后,将调用相册。但我无法将此图像分享给邮件。我使用MFMailComposeViewController 发送。
代码:
photopick= [UIButton buttonWithType:UIButtonTypeCustom];
[photopick setImage:[UIImage imageNamed:@"photo.png"] forState:UIControlStateNormal];
// [overlayButton setFrame:CGRectMake(80, 420, 60, 30)];
[photopick setFrame:CGRectMake(10, 10, 80, 50)];
[photopick addTarget:self action:@selector(showAlbum:) forControlEvents:UIControlEventTouchUpInside];
[[self view] addSubview:photopick];
-(void)showAlbum:(id)sender{
imagePicker=[[UIImagePickerController alloc]init];
imagePicker.delegate = self;
imagePicker.allowsEditing =NO;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
// imagePicker.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:imagePicker animated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
//release picker
[picker dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
//set image
[self.navigationController.navigationBar setHidden:NO];
// newImage = [[UIImageView alloc] initWithImage:[info objectForKey:UIImagePickerControllerOriginalImage]];
newImage = [[UIImageView alloc] initWithImage:[info objectForKey:UIImagePickerControllerOriginalImage]];
[newImage setFrame:CGRectMake(0, 0, 320, 568)];
// [newImage setUserInteractionEnabled:YES];
[self.view addSubview:newImage];
// [newImage release];
[picker dismissModalViewControllerAnimated:YES];
}
选择图片后,我还有其他按钮可以将 newImage(专辑图片)发送到邮件:
-(void)send:(id)sender{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"My image"];
UIImage *roboPic = [UIImage imageNamed:@"RobotWithPencil.jpg"];
NSData *imageData = UIImageJPEGRepresentation(roboPic, 1);
[picker addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"RobotWithPencil.jpg"];
NSString *emailBody = @"This is a cool image of a robot I found. Check it out!";
[picker setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:picker animated:YES];
}
但是我如何将专辑图片设置到 MFMailComposeViewController 内部。提到的一些文档使用了[UIImage imageNamed:@"img.png"]; 这里我没有imageName。我有相册中的图片
【问题讨论】:
-
保存图片到文档目录
-
我的要求是将图像保存到自定义相册并分享
-
使用您的自定义相册路径并使用该路径创建图像引用并使用 NSData 作为附件。
标签: iphone uiimagepickercontroller mfmailcomposeviewcontroller