如何从Objective-C中的.tiff图像中提取原始数据

时间:2022-12-09 08:58:53

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.

我有一些项目,我必须从生成的图像中处理一些原始数据,这些图像是.tiff格式。我只能访问图像位置。现在,我想从图像中提取一些原始信息,如图像中的像素数,不。每像素位数,没有。颜色成分等

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

我正在开发一个关于MAC OS的项目,因此,为了与Apple API交谈,正在使用Objective-C。

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

任何人都可以建议一些技术或一些Apple API,如果可能的话,这可以帮助我从图像中提取所需的?

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

P.S。:我实际上更喜欢.tiff格式,因为.jpeg是有损压缩。

1 个解决方案

#1


3  

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

也许这段代码会对你有所帮助,NSImage已经包含了宽度和高度,因此你可以计算像素数。

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);

#1


3  

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

也许这段代码会对你有所帮助,NSImage已经包含了宽度和高度,因此你可以计算像素数。

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);