vdh*_*ant 20 wpf file-io metadata image image-processing
链接这篇文章我希望能够读取图像文件的高度和宽度,而无需将整个文件读入内存.
在Frank Krueger的帖子中提到,有一种方法可以通过一些WPF Imaging类来实现.关于如何做到这一点的任何想法?
Ken*_*art 45
这应该这样做:
var bitmapFrame = BitmapFrame.Create(new Uri(@"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg"), BitmapCreateOptions.DelayCreation, BitmapCacheOption.None);
var width = bitmapFrame.PixelWidth;
var height = bitmapFrame.PixelHeight;
Run Code Online (Sandbox Code Playgroud)
Cha*_*lie 19
按照Juice爵士的建议,这里有一些替代代码可以避免锁定图像文件:
using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
var bitmapFrame = BitmapFrame.Create(stream, BitmapCreateOptions.DelayCreation, BitmapCacheOption.None);
var width = bitmapFrame.PixelWidth;
var height = bitmapFrame.PixelHeight;
}
Run Code Online (Sandbox Code Playgroud)