2

Here's the code I use:

NSImage *image = [[NSBundle bundleForClass:[self class]] imageForResource:@"test.jpg"];
NSData *originalData = [image TIFFRepresentationUsingCompression:NSTIFFCompressionJPEG factor:1.];

The originalData.length gives me 1802224 bytes (1.7MB). While the image size on the disk is 457KB. Why does TIFFRepresentation get larger and which representation I should use in order to get original image (i want to transfer image over the network)?

peetonn
  • 2,942
  • 4
  • 32
  • 49

1 Answers1

4

TIFF is much bigger than JPEG. No surprise there.

However, the answer to your actual question is: don't use any "representation". You have the data (namely, the file itself); send it! Don't turn the image file into an NSImage; grab it as an NSData.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • hm. so basically, in scenarios where user drags and drops an image, i'll just need to carry additional reference to a file dropped, alongside the image (which is used in UI). – peetonn Mar 08 '17 at 23:42
  • 1
    You _could_ make a JPEG representation of the image, but that seems rather wasteful when the file on disk _is_ a JPEG. – matt Mar 08 '17 at 23:44