为什么在 iOS 中通过调用 UIImageJPEGRepresentation 改变了图像的数据

Why the image's data has changed by calling UIImageJPEGRepresentation in iOS

这是一个只有 3,198 字节的 images.jpg,在像这样调用 UIImageJPEGRepresentation 之后:

它的数据大小是15,422字节。

这是为什么?我想知道,imageData使用的是哪种编码形式? UTF-8 或 UTF-16 或其他?而且,也许原始数据使用的是 unicode?不清楚,帮帮我,谢谢!!!

更新:

感谢@Fonix!

但是 PNG 呢? UIImagePNGRepresentation里面只有一个参数,我发现一个2.9M的png调用png的方法后会被压缩到62K。那么,如果我想获取SAME数据,我应该怎么做呢?

UIImageJPEGRepresentation 中使用小于 1 的值,因为这决定了压缩质量,所以您可能正在使用压缩的 jpg,并且基本上是未压缩的。 some documention

尝试使用此方法读取图像数据

NSURL *imgPath = [[NSBundle mainBundle] URLForResource:@"imageName" withExtension:@"png"];
NSString*stringPath = [imgPath absoluteString]; 

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:stringPath]];