Вопрос

I have some project wherein I have to manipulate some raw data from an image generated which is in .tiff format. I only have access to the image location. Now, I want to extract some raw info from the image like number of pixels in the image, no. of bits per pixel, no. of color components, etc.

I am working on a project on MAC OS and thus, to talk to Apple APIs, Objective-C is being used.

Can anyone suggest some techniques or some Apple APIs, if possible, which can assist me in extracting the desired from the image?

P.S.: I actually preferred .tiff format since .jpeg is a lossy compression.

Это было полезно?

Решение

Maybe this code will help you a bit, NSImage already contains width and height, so you can count number of pixels.

NSImage *image = [[NSImage alloc] initWithContentsOfFile:[@"~/Desktop/image.tiff" stringByExpandingTildeInPath]];
NSData *imageData = [image TIFFRepresentation];
CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)CFBridgingRetain(imageData), NULL);
CGImageRef imageRef =  CGImageSourceCreateImageAtIndex(source, 0, NULL);
NSUInteger numberOfBitsPerPixel = CGImageGetBitsPerPixel(imageRef);
NSLog(@"Number Of Bits Per Pixel %lu", (unsigned long)numberOfBitsPerPixel);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top