ios - 需要在不压缩的情况下在 NSData 中加载 "original"图像

标签 ios objective-c xcode

UIImageJPEGRepresentation 不返回原始图像。它将返回实际图像的压缩值。需要加载 NSData 中的原始图像数据集。有没有办法从图像中读取实际数据?

最佳答案

我认为您已尝试使用以下代码来使用 UIImageJPEGRepresentation

NSData *imageData = UIImageJPEGRepresentation(image, 1.0);

您可以像这样将图像转换为数据,反之亦然。

将 UIImage 转换为 NSData (png):

UIImage *image = [UIImage imageNamed:@"imageName.png"];
NSData *imageData = UIImagePNGRepresentation(image);

将 NSData 转换为 UIImage :

NSData *data = ... // data that you received
UIImage *image = [UIImage imageWithData:data];

关于ios - 需要在不压缩的情况下在 NSData 中加载 "original"图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40884916/

相关文章:

iphone - 推送通知是否需要服务器?

ios - 在 whereKey 中解析 iOS Swift 对象键

ios - 如何解决 iTunes/应用内购买的错误代码 -1202?

objective-c - 设置 QuickLook 插件的窗口大小

ios - 尝试使用在 Swift 中具有重复值的枚举

objective-c - Xcode 无法识别自定义类方法

ios - 将 UIViews 移动到另一个 UIViewController 中

ios - 如何在 Xcode 中为不同的目标设置单独的 LaunchScreen Storyboard

ios - 在 Swift 中按名称获取实例变量

ios - 如何按日期作为部分从核心数据中获取数据?