UIImage在iPhone上用文件名保存图像

我怎样才能保存一个图像(如使用UIImageWriteToSavedPhotosAlbum()方法)与我select的文件名私人/ var文件夹?

  • 我怎样才能得到通过iPhone中的照片库采摘的图像的名称?
  • UIImagePickerController不在iOS 8中呈现
  • iPhone“,超过最多5个过滤专辑列表试图注册。 这将失败。“错误
  • Swift PNG图像以不正确的方向保存
  • UIImagePickerController不填充屏幕
  • 在解散另一个之后立即呈现模态视图控制器
  • didFinishPickingMediaWithInfo返回零照片
  • UIImagePickerController错误:快照未呈现的视图会导致iOS 7中的空快照
  • 3 Solutions collect form web for “UIImage在iPhone上用文件名保存图像”

    肯尼,你有答案! 为了说明,我总是认为代码更有帮助。

    //I do this in the didFinishPickingImage:(UIImage *)img method NSData* imageData = UIImageJPEGRepresentation(img, 1.0); //save to the default 100Apple(Camera Roll) folder. [imageData writeToFile:@"/private/var/mobile/Media/DCIM/100APPLE/customImageFilename.jpg" atomically:NO]; 

    UIImageWriteToSavedPhotosAlbum()仅用于保存到照片相机胶卷。 要保存到自定义文件夹,您需要使用UIImageJPEGRepresentation()UIImagePNGRepresentation()将UIImage转换为NSData,然后将此NSData保存到您喜欢的任何位置。

    您可以使用下面的代码,而不使用ALAssetsLibrary …

     NSString *fileName; - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [picker dismissViewControllerAnimated:YES completion:^{ if( [picker sourceType] == UIImagePickerControllerSourceTypeCamera ) { UIImageWriteToSavedPhotosAlbum(image,nil, nil, nil); [self performSelector:@selector(GetImageName) withObject:nil afterDelay:0.5]; } else { NSURL *refURL = [info valueForKey:UIImagePickerControllerReferenceURL]; PHFetchResult *result = [PHAsset fetchAssetsWithALAssetURLs:@[refURL] options:nil]; fileName = [[result firstObject] filename]; } }]; -(void)GetImageName { NSString *str =@""; PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init]; fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]]; PHFetchResult *fetchResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:fetchOptions]; if (fetchResult != nil && fetchResult.count > 0) { str = [[fetchResult lastObject] filename]; } fileName = str; }