0

複数の画像をメールに添付するために使用していますが、すべてを一意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);
   }

}
4

2 に答える 2

2

このリンクからアプリを入手して ください 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];
}
于 2012-08-21T14:49:12.707 に答える
0

Objective-Zip、MiniZip、および ZLib をダウンロードして、このリンクからプロジェクトにドラッグしますhttp://code.google.com/p/objective-zip/downloads/list (Objective-zip). ファイルをインポートします: ZipFile .h、ZipException.h、FileInZipInfo.h、ZipWriteStream.h、ZipReadStream.h、zlib.h

次のコードを使用します。

NSString *stringPath1 = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]];
    NSString *FileName=[stringPath1 stringByAppendingPathComponent:@"Your file name"];


    NSString *stringPath=[stringPath1 stringByAppendingPathComponent:[@"Your file name" stringByAppendingFormat:@".zip"]];
    NSArray *files = [[NSFileManager defaultManager]contentsOfDirectoryAtPath:FileName error:&error];
    ZipFile *zipFile = [[ZipFile alloc]initWithFileName:stringPath mode:ZipFileModeCreate];

    for(int i = 0;i<files.count;i++){

        id myArrayElement = [files  objectAtIndex:i];
        NSLog(@"add %@", myArrayElement);

        NSString *path = [FileName stringByAppendingPathComponent:myArrayElement];
        NSDictionary *attributes = [[NSFileManager defaultManager]attributesOfItemAtPath:path error:&error];
        NSDate *Date = [attributes objectForKey:NSFileCreationDate];

        ZipWriteStream *streem = [zipFile writeFileInZipWithName:myArrayElement fileDate:Date compressionLevel:ZipCompressionLevelBest];
        NSData *data = [NSData dataWithContentsOfFile:path];
        [streem writeData:data];
        [streem finishedWriting];
    }

    [zipFile close];
于 2012-08-21T06:00:46.633 に答える