【问题标题】:Resize dimensions of a UIImage and save in an NSData调整 UIImage 的尺寸并保存在 NSData
【发布时间】:2014-02-25 11:24:19
【问题描述】:

我想调整 UIImage 的大小(高度和宽度)并将其存储在 NSData 中并使用新的度量值。示例:

[UIImage imageWithCGImage:[image CGImage] scale:compression orientation:UIImageOrientationUp]

这不会在转换为 NSData 时保留尺寸。有什么问题?

【问题讨论】:

    标签: ios uiimage nsdata dimensions


    【解决方案1】:

    scale 参数除了调整图像大小之外还有其他作用。举一个现实生活中的例子 - 加载视网膜图像时会涉及到比例。在这种情况下,图像尺寸减半,而数据量(以及实际尺寸)则没有。这只是在视网膜/非视网膜设备之间提供良好兼容性的一种巧妙方法。

    您需要创建更小的 CGContext 并重绘图像。即使在 SO 中也应该有很多例子。例如这里:The simplest way to resize an UIImage?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多