【问题标题】:Get image size in C# [duplicate]在 C# 中获取图像大小 [重复]
【发布时间】:2014-04-30 22:50:04
【问题描述】:

我想在 C# 中获取图像的大小。图像存储在C:\images\profile\7f155d5f-4622-4e71-b376-03cba1ccd39d.jpg。我想获取图像的宽度和高度。

所以任何人都可以帮助我或 我该怎么办?

【问题讨论】:

    标签: c#


    【解决方案1】:

    要获取存储在驱动器中的图像的高度和宽度,您可以使用以下代码:

    System.Drawing.Image img = System.Drawing.Image.FromFile(@"C:\images\profile\7f155d5f-4622-4e71-b376-03cba1ccd39d.jpg");
    MessageBox.Show("Width: " + img.Width + ", Height: " + img.Height);
    

    【讨论】:

      【解决方案2】:
      using(var image = new Bitmap(@"C:\images\profile\7f155d5f-4622-4e71-b376-03cba1ccd39d.jpg"))
      {
          var height = image.Height;
          var width = image.Width;
      }
      

      Edit 将@ 添加到字符串以转义反斜杠。使用块添加

      【讨论】:

        【解决方案3】:

        你可以使用Bitmap类:

        Bitmap bitmap = new Bitmap(path);
        
        int width = bitmap.Width;
        int height = bitmap.Height;
        

        不要忘记在您的项目中引用System.Drawing

        【讨论】:

          【解决方案4】:
          Image _img=new Image();    
          BitmapImage bitmap = new BitmapImage(new Uri(filePath, UriKind.Absolute));           
          _img.Source = bitmap;
          int _width=_img.Width
          int _height=_img.Height;
          

          【讨论】:

            猜你喜欢
            • 2017-06-03
            • 1970-01-01
            • 2013-04-12
            • 1970-01-01
            • 2012-01-24
            • 2012-09-15
            • 2012-05-07
            • 1970-01-01
            • 2017-10-05
            相关资源
            最近更新 更多