Iphone 如何在相册中以照片的名称保存和检索照片

Iphone 如何在相册中以照片的名称保存和检索照片,iphone,photo-gallery,photolibrary,Iphone,Photo Gallery,Photolibrary,我有以下疑问: 我们可以用“特定名称”将照片(图像)保存到相册中,还是可以在保存后访问照片的名称 我们可以从相册中访问具有其名称的照片吗 请帮忙 提前感谢。这是使用用户指定名称编写图像的代码 // Create paths to output images NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.png"]; NSString *jpgPath = [N

我有以下疑问:

  • 我们可以用“特定名称”将照片(图像)保存到相册中,还是可以在保存后访问照片的名称

  • 我们可以从相册中访问具有其名称的照片吗

  • 请帮忙


    提前感谢。

    这是使用用户指定名称编写图像的代码

     // Create paths to output images
     NSString  *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.png"];
     NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"];
    
     // Write a UIImage to JPEG with minimum compression (best quality)
     // The value 'image' must be a UIImage object
     // The value '1.0' represents image compression quality as value from 0.0 to 1.0
     [UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES];
    
     // Write image to PNG
     [UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];
    
     // Let's check to see if files were successfully written...
    
     // Create file manager
     NSError *error;
     NSFileManager *fileMgr = [NSFileManager defaultManager];
    
     // Point to Document directory
     NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    
     // Write out the contents of home directory to console
     NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);
    

    这是使用用户指定的名称编写图像的代码

     // Create paths to output images
     NSString  *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.png"];
     NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"];
    
     // Write a UIImage to JPEG with minimum compression (best quality)
     // The value 'image' must be a UIImage object
     // The value '1.0' represents image compression quality as value from 0.0 to 1.0
     [UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES];
    
     // Write image to PNG
     [UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];
    
     // Let's check to see if files were successfully written...
    
     // Create file manager
     NSError *error;
     NSFileManager *fileMgr = [NSFileManager defaultManager];
    
     // Point to Document directory
     NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    
     // Write out the contents of home directory to console
     NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);
    

    使用委托
    UIImagePickerControllerDelegate
    调用相机或图像库

    调用摄影机:

    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    isCamera = YES;
    
    [self presentModalViewController:picker animated:YES];
    
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
    
    [picker setAllowsEditing:YES];
    
    [self presentModalViewController:(UIViewController*)picker animated:YES];
    
    调用库:

    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    isCamera = YES;
    
    [self presentModalViewController:picker animated:YES];
    
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
    
    [picker setAllowsEditing:YES];
    
    [self presentModalViewController:(UIViewController*)picker animated:YES];
    
    完成后,将调用委托方法:

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    
    要将图像写入库,请使用:

    UIImageWriteToSavedPhotosAlbum(currentImage, nil, nil, nil);
    

    或者将从照片库中拾取的选定图像保存到
    UIImage
    并对其执行进一步操作。

    使用委托
    UIImagePickerControllerDelegate
    调用相机或图像库

    调用摄影机:

    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    isCamera = YES;
    
    [self presentModalViewController:picker animated:YES];
    
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
    
    [picker setAllowsEditing:YES];
    
    [self presentModalViewController:(UIViewController*)picker animated:YES];
    
    调用库:

    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    isCamera = YES;
    
    [self presentModalViewController:picker animated:YES];
    
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
    
    [picker setAllowsEditing:YES];
    
    [self presentModalViewController:(UIViewController*)picker animated:YES];
    
    完成后,将调用委托方法:

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    
    要将图像写入库,请使用:

    UIImageWriteToSavedPhotosAlbum(currentImage, nil, nil, nil);
    

    或者将从照片库中选择的图像保存到
    UIImage
    ,并对其执行进一步操作。

    感谢您回答我的问题。实际上,我需要用特定的名称将照片保存到相册中,而不是文档目录。谢谢您回答我的问题。实际上,我需要用特定的名称将照片保存到相册中,而不是文档目录。@Janinak:Hi,我知道如何使用imagePicker和保存图像等。但我的疑问是,如何保存和访问具有特定名称的图像。您的程序不允许在其“沙盒”之外保存内容。@Janinak:Hi,我知道如何使用imagePicker和保存图像等,但我的疑问是,如何保存和访问具有特定名称的图像。您的程序不允许在其“沙盒”之外保存内容。