我能够通过以下代码在图片框中显示图片,而无需检查文件大小:
private void button3_Click_1(object sender, EventArgs e)
{
try
{
//Getting The Image From The System
OpenFileDialog open = new OpenFileDialog();
open.Filter =
"Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
Bitmap img = new Bitmap(open.FileName);
pictureBox2.Image = img;
}
}
catch (Exception)
{
throw new ApplicationException("Failed loading image");
}
}
在将图片显示在图片框之前,我想检查图片的大小,例如是否为2MB或4MB。我还想检查图像的宽度和高度。