メモリにロードせずにモノタッチで画像ファイルの画像サイズを取得する方法は?
Apple のドキュメントとこのブログ投稿に示されているように、MonoTouch.ImageIO 名前空間から CGImageSource を使用しようとしました。
しかし、このコードは機能しません:
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);
}
文字列にキャストしても違いはありません。フィールドは空を返します。
どんな助けでも大歓迎です、ありがとう!