0

我使用下面的代码从图库中选择照片或直接使用相机

- (void)actionSheet:(UIActionSheet *)actionSheet 
         clickedButtonAtIndex:(NSInteger)buttonIndex {

    UIImagePickerController *imagePickerController = 
      [[UIImagePickerController alloc]init];

    imagePickerController.delegate = self;
    if (buttonIndex == 0) {
        photoButtonNum=0;
        [self presentViewController:imagePickerController 
                           animated:YES 
                         completion:nil];
        imagePickerController.sourceType =  
          UIImagePickerControllerSourceTypePhotoLibrary;
    } else if (buttonIndex == 1) {
        photoButtonNum=1;
        [self presentViewController:imagePickerController 
                           animated:YES 
                         completion:nil];
        imagePickerController.sourceType =  
          UIImagePickerControllerSourceTypeCamera;
    }
}

我正在寻找创建我自己的应用程序的自定义目录(文件夹)以将挑选的照片保存在 iPhone 中。我需要你的帮助

  1. 创建我自己的应用程序的自定义目录
  2. 想要将挑选的照片保存在该自定义目录中。

我是iPhone开发中的新人,所以等待您的宝贵帮助。提前致谢。

4

2 回答 2

1

该站点有助于您在目录中创建和保存照片

而且您还可以使用以下代码。

- (void)imagePickerController:(UIImagePickerController *)picker 
          didFinishPickingMediaWithInfo:(NSDictionary *)info {
     UIImage *pickedImage = 
       [info objectForKey:UIImagePickerControllerOriginalImage];
     NSData *imageData = UIImagePNGRepresentation(pickedImage);

     NSString *documentsDirectory = 
       [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
                                            NSUserDomainMask, 
                                            YES) lastObject];
     NSString *path = [documentsDirectory 
       stringByAppendingPathComponent:@"imageName.png"];

    NSError * error = nil;
    [imageData writeToFile:storePath options:NSDataWritingAtomic error:&error];

    if (error != nil) {
      NSLog(@"Error: %@", error);
      return;
    }
}
于 2013-02-11T04:32:50.440 回答
1

iOS 5 为您提供了使用添加自定义相册的功能ALAssetsLibrary

这是iOS5的教程:将照片保存在自定义相册中


编辑

如果链接变为非活动状态

在 .h 文件中创建 ivar

ALAssetsLibrary* library;

然后在你的代码中可能viewDidLoad

library = [[ALAssetsLibrary alloc] init];

然后在您的委托方法中

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    [self.library saveImage:image toAlbum:@"Touch Code Magazine" withCompletionBlock:^(NSError *error) {
        if (error!=nil) {
            NSLog(@"Big error: %@", [error description]);
        }
    }];

    [picker dismissModalViewControllerAnimated:NO];
}
于 2013-02-11T04:35:29.497 回答