ios - 在 iPhone 中创建自定义图片库

标签 ios iphone objective-c uiimagepickercontroller

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

- (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 开发的新手,期待您的宝贵帮助。 提前致谢。

最佳答案

本站有助于您创建和保存Photo in your Directory

你也可以使用下面的代码。

- (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;
    }
}

关于ios - 在 iPhone 中创建自定义图片库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14805832/

相关文章:

用于白标应用程序的 iOS 静态库代码库

ios - Swift-从随机创建的文档ID(Firestore)中获取字段

iphone - UITableView分隔符样式 "Single Line Etched"无法正常工作

iphone - 将 NSString 转换为 cString 以与 CGContextShowTextAtPoint 一起使用

ios - NSOperationQueue 和 NSURLSession 有什么区别?

ios - 不同 IOS 应用之间的 Firebase NSKeyedUnarchiver 终止

ios - 处理异步错误处理

iPhone 在应用程序启动时出现黑屏

iphone - iOS XCODE崩溃并显示错误:调度队列:com.apple.root.default-qos

iphone - 弱 self 是否必要(performSelector)