【发布时间】:2014-04-30 22:50:04
【问题描述】:
我想在 C# 中获取图像的大小。图像存储在C:\images\profile\7f155d5f-4622-4e71-b376-03cba1ccd39d.jpg。我想获取图像的宽度和高度。
所以任何人都可以帮助我或 我该怎么办?
【问题讨论】:
标签: c#
我想在 C# 中获取图像的大小。图像存储在C:\images\profile\7f155d5f-4622-4e71-b376-03cba1ccd39d.jpg。我想获取图像的宽度和高度。
所以任何人都可以帮助我或 我该怎么办?
【问题讨论】:
标签: c#
要获取存储在驱动器中的图像的高度和宽度,您可以使用以下代码:
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);
【讨论】:
using(var image = new Bitmap(@"C:\images\profile\7f155d5f-4622-4e71-b376-03cba1ccd39d.jpg"))
{
var height = image.Height;
var width = image.Width;
}
Edit 将@ 添加到字符串以转义反斜杠。使用块添加
【讨论】:
你可以使用Bitmap类:
Bitmap bitmap = new Bitmap(path);
int width = bitmap.Width;
int height = bitmap.Height;
不要忘记在您的项目中引用System.Drawing。
【讨论】:
Image _img=new Image();
BitmapImage bitmap = new BitmapImage(new Uri(filePath, UriKind.Absolute));
_img.Source = bitmap;
int _width=_img.Width
int _height=_img.Height;
【讨论】: