0

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

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

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

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

4

1 回答 1

3

也许这段代码会对您有所帮助,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);
于 2013-09-26T10:40:10.963 回答