将UIIMAGE转换为数据,然后返回UIIMAGE在字节(size)中有所不同
我遇到了一个问题,即将uiimage
转换为data
,然后回到uiimage
使最后一个变为更大的[字节]。
示例(将任何大于3MB的照片添加到您的设备中):
guard let image = UIImage(named: "image_larger_than_3MB"),
let data = image.jpegData(compressionQuality: 1)
else { print("failure"); return }
print(data.count)
guard let imageBack = UIImage(data: data),
let dataBack = imageBack.jpegData(compressionQuality: 1)
else { print("failure 2"); return }
print(dataBack.count)
在我的情况下,我会收到以下控制台输出:
5304493 // = 5,06 MB // size before conversion
5575422 // = 5,32 MB // size after conversion
因此,初始图像的大小为5,06 MB。然后,我以最大质量将其转换为数据。然后,我再次将其转换为图像,并且大小更大,因为它是5,32 MB。问题随图像的大小而上升。
我了解问题可能与同时使用的压缩有关。无论如何,令我惊讶的是,大小更大而不是较小。
- 使用.jpeg Compression ..?
- 为什么尺寸增加(我知道它可以减少)?
I faced a problem, that converting the UIImage
to Data
and back to UIImage
causes the last one to be larger [bytes].
Example (add to your device any photo which is larger than 3MB):
guard let image = UIImage(named: "image_larger_than_3MB"),
let data = image.jpegData(compressionQuality: 1)
else { print("failure"); return }
print(data.count)
guard let imageBack = UIImage(data: data),
let dataBack = imageBack.jpegData(compressionQuality: 1)
else { print("failure 2"); return }
print(dataBack.count)
In my case I receive the following console output:
5304493 // = 5,06 MB // size before conversion
5575422 // = 5,32 MB // size after conversion
So the initial image was of size 5,06 MB. Then I converted it to data with max quality. Then I convert it once again to image, and the size is larger, because it's 5,32 MB. The issue rises with the size of the image.
I understand that the issue is probably connected with compression used in the meantime. Anyway, it surprises me that the size is larger instead of smaller.
- Is there any way to maintain the second
jpg
size same to the initialjpg
image when using .jpeg compression..? - Why the size increased (I understand it could decrease)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论