【问题标题】:How can I extract raw data from a .tiff image in Objective-C如何从 Objective-C 中的 .tiff 图像中提取原始数据
【发布时间】:2013-10-02 02:57:16
【问题描述】:

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

我正在开发一个有关 MAC OS 的项目,因此,为了与 Apple API 通信,正在使用Objective-C

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

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

【问题讨论】:

    标签: objective-c image tiff feature-extraction


    【解决方案1】:

    也许这段代码会对你有所帮助,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 感谢您的回答.. 这是有效的。您能否告诉我如何从NSDataNSImage 中提取pixelDataType 信息?
    • 如前所述here
    • 另外,如何获取图片中的行数?
    • 关于你的链接有一个完整的例子,它显示了如何做到这一点:developer.apple.com/library/mac/samplecode/VirtualScanner/…
    • 项目中没有提到我需要的信息:图片中的number of rowspixelDatatype。无论如何,我现在可以操纵pixelDataType。那么,关于no. of rows- 是否与图像的height 相同......?(我不这么认为)。如果没有,那我怎样才能得到这些信息?
    猜你喜欢
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    • 2021-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-24
    • 1970-01-01
    相关资源
    最近更新 更多