本文介绍了检查的图像的宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我能够不通过下面的代码检查文件大小来显示图片框的图片:
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, 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 。我也想检查宽度和高度的形象。
I want to check the image size for example whether it is 2MB or 4MB before displaying in the picture box. i also want to check the width and height 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;
这篇关于检查的图像的宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!