How can I get the resolution of an image? (JPEG, GIF, PNG, JPG)

后端 未结 3 747
醉梦人生
醉梦人生 2020-12-30 13:12

I found this method:

Graphics g = e.Graphics;
Bitmap bmp = new Bitmap(\"winter.jpg\");
g.DrawImage(bmp, 0, 0);
Console.WriteLine(\"Screen resolution: \" + g.         


        
3条回答
  •  余生分开走
    2020-12-30 13:31

    To get the size:

    string path = @"C:\winter.jpg";
    Image img = Image.FromFile(path);
    Console.WriteLine("Image Width: " + img.Width); //equals img.Size.Width
    Console.WriteLine("Image Height: " + img.Height); //equals img.Size.Height
    

    Here's a full list of System.Drawing.Image properties, if case want to display others.

    I'm not sure if there's a quicker way for an entire directory, with Windows Vista/7 there may be a newer API that contains this info, haven't come across it though.

提交回复
热议问题