【问题标题】:Save last clicked image from gallery to document directory in ios将上次单击的图像从图库保存到 ios 中的文档目录
【发布时间】:2016-04-20 19:01:29
【问题描述】:

我想将保存在照片库中的最后点击的图像保存到文档目录。我怎样才能实现它。?

【问题讨论】:

  • 我认为你的意思是内存磁盘空间。我对这个假设是否正确?我能想到的唯一解释是照片库中的图像被压缩了。
  • @ok404 - 是的,我指的是内存磁盘空间。你有什么解决办法吗?

标签: ios objective-c ipad uiimage uikit


【解决方案1】:

在您的代码中将 NSData *dataForJPEGFile = UIImageJPEGRepresentation(mimage, 1.0); 更改为

NSData *dataForJPEGFile = UIImageJPEGRepresentation(mimage, 0.5);

此代码 0.5 表示将压缩 50% 的图像。

    - (void)saveImageToDocumentsDirectory:(UIImage *)mimage withFileName:(NSString *)fileName {
                NSData *dataForJPEGFile = UIImageJPEGRepresentation(mimage, 0.5);
                [dataForJPEGFile writeToFile:[self getDirectoryFilePath:fileName] atomically:YES];
}

【讨论】:

  • 感谢您的回答。但我需要 100% 质量而不是 50% 的图像。
  • 试试UIImageJPEGRepresentation(mimage, 1.0)
【解决方案2】:

确保您的相册中保存的照片大小和质量正确。 iOS有问题,见链接:UIImageWriteToSavedPhotosAlbum saves to wrong size and quality

对于某些图片,PNG 格式会小于 JPG 格式。您可以尝试通过 UIImagePNGRepresentation 保存图片。

【讨论】:

    猜你喜欢
    • 2015-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多