Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios NSFileManager>;属性FiteMatPath>;图像维度_Ios_Objective C_Nsfilemanager - Fatal编程技术网

Ios NSFileManager>;属性FiteMatPath>;图像维度

Ios NSFileManager>;属性FiteMatPath>;图像维度,ios,objective-c,nsfilemanager,Ios,Objective C,Nsfilemanager,如何获取保存在文档目录中的图像文件的尺寸 通过使用以下代码,我可以获得其他属性,如NSFileCreationDate和NSFileSize NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:imageFile error:nil]; NSDate *date = (NSDate*)[attributes objectForKey:NSFileCreationDate]; 您不能在

如何获取保存在文档目录中的图像文件的尺寸

通过使用以下代码,我可以获得其他属性,如NSFileCreationDate和NSFileSize

NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:imageFile error:nil];
NSDate *date = (NSDate*)[attributes objectForKey:NSFileCreationDate];

您不能在NSFileManager级别执行此操作。您需要读取和解析文件的内容——至少是标题

如何执行此操作取决于文件的类型


最简单的方法是将其作为图像加载,然后查询图像。

正如邓肯所说,你不能这样做。但是可以使用
ImageIO
框架。请尝试下面的代码

NSURL *imageFileURL = [NSURL fileURLWithPath:...]; // Put your image in a URL
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((CFURLRef)imageFileURL, NULL);
if (imageSource == NULL) {
// Error loading image
...
return;
}

CGFloat width = 0.0f, height = 0.0f;
CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);
if (imageProperties != NULL) {
CFNumberRef widthNum  = CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelWidth);
if (widthNum != NULL) {
    CFNumberGetValue(widthNum, kCFNumberCGFloatType, &width);
}

CFNumberRef heightNum = CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight);
if (heightNum != NULL) {
    CFNumberGetValue(heightNum, kCFNumberCGFloatType, &height);
}

CFRelease(imageProperties);
}

NSLog(@"Image dimensions: %.0f x %.0f px", width, height);

听起来不错。考虑使用
ImageIO
框架。你说什么?