【问题标题】:How decrease the size of image jpeg/png如何减小图像 jpeg/png 的大小
【发布时间】:2012-11-08 05:59:55
【问题描述】:

我通过传递两个参数使用以下方法创建图像,一个是UIImage对象是imagdata,NSString对象是storeImage

JPG:[UIImageJPEGRepresentation(imageData, 1.0) writeToFile:storeImage atomically:YES]; 要么 PNG:[UIImagePNGRepresentation(imageData) writeToFile:storeImage atomically:YES];

我的问题是,在我使用上述方法后,原始图像大小为 2.1 MB,模拟器中的图像大小为 4.2 MB。

我不想使用任何压缩方法,也不想损失任何图像质量。我想复制给定路径中的图像。实际大小。

【问题讨论】:

  • 或许-[NSFileManager copyItemAtPath:toPath:error:]; 更合适?
  • 如果您不想损失质量,请不要使用 JPEG。

标签: iphone ios ios4 ios-simulator


【解决方案1】:

使用图像的简单数据对象。尝试以下代码,其中 imageData 在 NSData 对象中。

[imageData writeToFile:storeImage atomically:YES];

【讨论】:

    【解决方案2】:

    你能告诉我原始尺寸和格式是什么吗?
    减小尺寸的一种方法是降低质量。

    [UIImageJPEGRepresentation(imageData, 0.5) writeToFile:storeImage atomically:YES]
    

    另一种方法是使用 ImageIO 框架。

    【讨论】:

      最近更新 更多