I scanned an image (.tiff
) with Macintosh millions of colors
which means 24 bits per pixel
. The scanned image that I am getting has the following attributes: size = 330KB
and dimensions = 348 * 580 pixels
. Since, there are 24 bits per pixel, the size should actually be 348 * 580 * 3 = 605KB
.
Is there something incorrect? I also used this code to extract the image raw data from the url of the image scanned:
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);
NSUInteger width = CGImageGetWidth(imageRef);
From this code also, I am getting the same info about the width, height and number of bits per pixel in the image.
Basically, I have to use this image's information and reproduce it somewhere else in some other form, so if I'll not be able to get the correct the information, the final product is not reproducible. What can be wrong here?
P.S.: If some other information is needed to answer the question, then I'll be happy to provide that.
The most common image formats jpg
, png
and tiff
compress the image which is why the filesize is lower than w*h*bits
per pixel.
JPEG use lossy compression, PNG use lossless compression and TIFF can be uncompressed, use lossy compression or lossless compression.
Lossy compression means that some color imformation is lost in the compression so the image won't look exactly like it did before compression but you can reduce the file size even further using lossy compression.
An example of lossless compression is run length encoding which basically means that if you have several consequtive pixels with the same color you just say that you have N
pixels with value (R,G,B)
instead of saying (R,G,B),(R,G,B),...,(R,G,B)