如何获得图像文件的图像大小, 而不装入内存?
我试图使用来自Monotouch. ImagieIO 命名空间的CGIMAGE来源,
但这个代码不起作用:
public Size GetImageSizeFromImageFile (string image_file_path)
{
CGImageSource imageSource = CGImageSource.FromUrl (NSUrl.FromFilename (image_file_path));
if (imageSource == null) {
// Error loading image
Console.WriteLine ("Error loading image info for file: " + image_file_path);
return Size.Empty;
}
NSDictionary imageProperties = new NSDictionary ();
imageSource.CopyProperties (imageProperties, 0);
int width = (int)imageProperties.ValueForKey (new NSString ("kCGImagePropertyPixelWidth"));
int height = (int)imageProperties.ValueForKey (new NSString ("kCGImagePropertyPixelHeight"));
Console.WriteLine (@"Image " + image_file_path + " dimensions: " + width + " x " + height+" px");
imageProperties.Dispose ();
return new Size(width, height);
}
输入字符串不会有什么区别, 字段返回空 。
感谢任何帮助,谢谢!