pee*_*onn 2 macos objective-c nsimage nsimagerep
这是我使用的代码:
NSImage *image = [[NSBundle bundleForClass:[self class]] imageForResource:@"test.jpg"];
NSData *originalData = [image TIFFRepresentationUsingCompression:NSTIFFCompressionJPEG factor:1.];
Run Code Online (Sandbox Code Playgroud)
给originalData.length了我 1802224 字节 (1.7MB)。而磁盘上的镜像大小为457KB。为什么TIFFRepresentation会变大以及我应该使用哪种表示形式才能获得原始图像(我想通过网络传输图像)?
TIFF 比 JPEG 大得多。这并不奇怪。
但是,您实际问题的答案是:不要使用任何“表示”。您拥有数据(即文件本身);发送!不要将图像文件转为 NSImage;将其作为 NSData 获取。