【问题标题】:How can I check if a file is an image file without checking the path extension?如何在不检查路径扩展名的情况下检查文件是否为图像文件?
【发布时间】:2014-08-18 04:54:11
【问题描述】:

我需要区分文本文件图像文件,而不需要查看它们的路径扩展名。

我想检查文件是否真的是图像。 搜索后,可以从路径扩展名中检查 mimetype,但是,我想要验证文件内容本身的解决方案。

【问题讨论】:

  • Get the type of a file in Cocoa 的可能重复项
  • 我在问题描述中提到我需要不查看其文件扩展名的解决方案。建议问题中的解决方案无法满足我的需求,因为它认为文件扩展名是说明文件类型的一个因素。

标签: objective-c uiimage file-type


【解决方案1】:
UIImage *image = [UIImage imageNamed:@"SomeFile.xyz"];
if (image == nil) {
    NSLog(@"This is probably text file");
}

如果 image 为 nil,则表示该文件可能是文本或其他类型的文件。

【讨论】:

    猜你喜欢
    • 2015-06-30
    • 2019-04-22
    • 2013-08-31
    • 1970-01-01
    • 2013-07-18
    • 2022-01-18
    • 2011-01-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多