gpt4 book ai didi

ios - 如何在不加载图像文件的情况下获取图像文件的图像大小?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:50:44 26 4
gpt4 key购买 nike

如何在不加载内存的情况下获取图像文件的图像大小?

我尝试使用 MonoTouch.ImageIO 命名空间中的 CGImageSource,如 Apple 文档和此博客文章中所述:

oleb.net

但是这段代码不起作用:

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);
}

转换为字符串没有任何区别,该字段返回空。

感谢任何帮助,谢谢!

最佳答案

最新的 MonoTouch 版本使得使用新的 GetProperties 方法获取图像属性变得更加容易。例如

using (var src = CGImageSource.FromUrl (NSUrl.FromFilename (filename))) {
CGImageOptions options = new CGImageOptions () { ShouldCache = false };
// do not forget the '0' image index or you won't get what you're looking for!
using (var p = src.GetProperties (options, 0)) {
Console.WriteLine ("{0}x{1}", p.PixelWidth, p.PixelHeight);
}
}

关于ios - 如何在不加载图像文件的情况下获取图像文件的图像大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10753108/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com