gpt4 book ai didi

iphone - 将多个图像附加到电子邮件

转载 作者:行者123 更新时间:2023-11-28 22:50:48 27 4
gpt4 key购买 nike

我正在使用 ELCimagepicker 将多个图像附加到电子邮件中,但我不确定如何使每个 NSData 都是唯一的,以便我可以将它们附加到我的电子邮件中。

>

- (void)launchController {
ELCAlbumPickerController *albumController = [[ELCAlbumPickerController alloc] initWithNibName:@"ELCAlbumPickerController" bundle:[NSBundle mainBundle]];
ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initWithRootViewController:albumController];
[albumController setParent:elcPicker];
[elcPicker setDelegate:self];
[self presentModalViewController:elcPicker animated:YES];
}

- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info {

[self dismissModalViewControllerAnimated:YES];
int i = 0;
for(NSDictionary *dict in info) {
i++;
UIImageView *imageview = [[UIImageView alloc] initWithImage:[dict objectForKey:UIImagePickerControllerOriginalImage]];
NSData *name = UIImageJPEGRepresentation(imageview, 1.0);
}

}

最佳答案

从此链接获取应用程序 https://github.com/elc/ELCImagePickerController

以及代码的后续更改

使用for循环

-(IBAction)launchController 

{

ELCAlbumPickerController *albumController = [[ELCAlbumPickerController alloc] initWithNibName:@"ELCAlbumPickerController" bundle:[NSBundle mainBundle]];
ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initWithRootViewController:albumController];
[albumController setParent:elcPicker];
[elcPicker setDelegate:self];

ELCImagePickerDemoAppDelegate *app = (ELCImagePickerDemoAppDelegate *)[[UIApplication sharedApplication] delegate];
[app.viewController presentModalViewController:elcPicker animated:YES];
[elcPicker release];
[albumController release];

[self buttonPressed];

}



- (void)buttonPressed
{
// Create image picker controller
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

// Set source to the camera
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

// Delegate is self
imagePicker.delegate = self;

// Allow editing of image ?
imagePicker.allowsImageEditing = NO;

// Show image picker
[self presentModalViewController:imagePicker animated:YES];
}







- (void)emailImage:(UIImage *)image
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

// Set the subject of email
[picker setSubject:@"Picture from my iPhone!"];

// Add email addresses
// Notice three sections: "to" "cc" and "bcc"
[picker setToRecipients:[NSArray arrayWithObjects:@"emailaddress1@domainName.com", @"emailaddress2@domainName.com", nil]];
[picker setCcRecipients:[NSArray arrayWithObject:@"emailaddress3@domainName.com"]];
[picker setBccRecipients:[NSArray arrayWithObject:@"emailaddress4@domainName.com"]];

// Fill out the email body text
NSString *emailBody = @"I just took this picture, check it out.";


for (int i=0; i<[imagedelegate.imgarray count]; i++)
{

UIImageView *image=[[UIImageView alloc] init];
image=[imagedelegate.imgarray objectAtIndex:i];

// This is not an HTML formatted email
[picker setMessageBody:emailBody isHTML:NO];

// Create NSData object as PNG image data from camera image
NSData *data = UIImagePNGRepresentation(image);

// Attach image data to the email
// 'CameraImage.png' is the file name that will be attached to the email
[picker addAttachmentData:data mimeType:@"image/png" fileName:@"CameraImage"];

// Show email view
[self presentModalViewController:picker animated:YES];

// Release picker
[picker release];
}
}



- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

// Dismiss the camera
[self dismissModalViewControllerAnimated:YES];

// Pass the image from camera to method that will email the same
// A delay is needed so camera view can be dismissed
[self performSelector:@selector(emailImage:) withObject:image afterDelay:1.0];

// Release picker
[picker release];
}

关于iphone - 将多个图像附加到电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12047448/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com