检查图像的宽度和高度
我可以通过以下代码在图片框中显示图片而无需检查文件大小:
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 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");
}
}
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
位图
将保存图像的高度和宽度。使用
FileInfo
< code>Length 属性来获取文件大小。The
Bitmap
will hold the height and width of the image.Use the
FileInfo
Length
property to get the file size.我有一个类似的问题,我写了一个方法来检测图片是否是横向的。
如果它可以帮助你的话。
I had a similar issue and I wrote a method to detect if the picture is landscape or not.
If it can help you.
UWP 目前有一个很好的接口来获取图像属性。
UWP has currently a nice interface to obtain image properties.