Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check File Size or dimension?

Tags:

c#

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

I am using this code but not find how to find size or dimension of image?

like image 421
Andy Avatar asked Oct 28 '25 16:10

Andy


2 Answers

Answered as a part of this question: 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;
like image 155
Zdeslav Vojkovic Avatar answered Oct 31 '25 05:10

Zdeslav Vojkovic


use FileInfo given path of this file and use Length as

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);
like image 32
Prasad Avatar answered Oct 31 '25 06:10

Prasad