I have an image in the form of an NSURL
as input. I converted this url to NSImage
and then to NSData
from which I could get CGImageRef
. This imageRef helped me extracting the raw data information from the image such as the height, width, bytesPerRow, etc.
Here's the code that I used:
NSString * urlName = [url path];
NSImage *image = [[NSImage alloc] initWithContentsOfFile:urlName];
NSData *imageData = [image TIFFRepresentation];
CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)CFBridgingRetain(imageData), NULL);
CGImageRef imageRef = CGImageSourceCreateImageAtIndex(source, 0, NULL);
NSUInteger numberOfBitsPerPixel = CGImageGetBitsPerPixel(imageRef);
NSUInteger height = CGImageGetHeight(imageRef);
...
...
Now, I checked the size of the image using:
int sz = [imageData length];
which is different from - int sz' = bytesPerRow * height
I cannot understand why is there such a difference. And sz
is actually half of sz'
.
Am I making some mistake while extracting various info? From what I can get is that maybe while conversion of image to NSData
some decompressions are done. In such a case, what should I use that can get me the reliable data.
I am new to the world image processing in Objective-C
, so please bear with me!
P.S. I actually checked the size of the file that I am getting as input in the form of NSURL
which is same as sz
.