Check the width and height of an image

后端 未结 3 1792
被撕碎了的回忆
被撕碎了的回忆 2021-01-17 10:10

I am able to display the picture in the picture box without checking the file size by the following code:

private void button3_Click_1(object sender, EventAr         


        
3条回答
  •  别那么骄傲
    2021-01-17 10:42

    The Bitmap will hold the height and width of the image.

    Use the FileInfo Length property to get the file size.

    FileInfo file = new FileInfo(open.FileName);
    var sizeInBytes = file.Length;
    
    Bitmap img = new Bitmap(open.FileName);
    
    var imageHeight = img.Height;
    var imageWidth = img.Width;
    
    pictureBox2.Image = img;
    

提交回复
热议问题