var dlg = new Microsoft.Win32.OpenFileDialog();
dlg.Filter = "(*.JPG;*.GIF)|*.JPG;*.GIF";
dlg.ShowDialog();
if (string.IsNullOrEmpty(dlg.FileName)) return;
var fs = new FileStream(dlg.FileName, FileMode.Open, FileAccess.Read);
var data = new byte[fs.Length];
fs.Read(data, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
我正在使用此代码但未找到如何查找图像的大小或尺寸?
答案 0 :(得分:5)
作为此问题的一部分回答:Limit image size
string filename = // get it from OpenFileDialog
var length = new FileInfo(filename).Length;
Image img = Image.FromFile(filename);
var w = img.Width;
var h = img.Height;
答案 1 :(得分:2)
使用FileInfo给定此文件的路径并使用Length作为
var dlg = new Microsoft.Win32.OpenFileDialog();
dlg.Filter = "(*.JPG;*.GIF)|*.JPG;*.GIF";
dlg.ShowDialog();
if (string.IsNullOrEmpty(dlg.FileName))
return;
FileInfo info = new FileInfo(dlg.FileName);
Console.Write("Length In Bytes:"+info.Length);