如何验证图像和裁剪 [英] How to validate image and crop
问题描述
我想验证图片,验证其高度和宽度 用户尝试上传时,如果使用upload 作为定义图像大小,以便他可以允许做裁剪 as 每个定义高度和宽度我编写代码用于图像验证,但它不起作用我执行调试但代码不在如果条件我突出显示
我尝试过:
OpenFileDialog openfd = new OpenFileDialog();
openfd.Filter =仅图片。| * .jpg; * .jpeg; * .png; * .gif;;
if(openfd.ShowDialog()== DialogResult.OK )
{
** if(pictureBox6.Width< 120&& pictureBox6.Height< 173)
{
MessageBox.Show(大小无效);
} **
其他
{
pictureBox6.Image = new Bitmap(openfd.FileName);
}
}
您只需要一个图像(在本例中为位图),而不是PictureBox
,这是一个渲染图像的控件,一个纯粹的冗余控件,由于某些原因,这个论坛的许多查询者都会产生巨大的混淆。
// ...
var myBitmap = new 位图(openfd.FileName);
int width = myBitmap.Width;
int height = myBitmap.Height;
-SA
i want to validate image , validate its height and width when user trying to upload, also if use upload as define image size so he can be allow to do crop as per define height and width i wrote code for image validation but its not working also i do debugging but code not going inside if condition which i highlighted
What I have tried:
OpenFileDialog openfd = new OpenFileDialog();
openfd.Filter = "Image only. |*.jpg; *.jpeg; *.png; *.gif;";
if (openfd.ShowDialog() == DialogResult.OK)
{
**if (pictureBox6.Width < 120 && pictureBox6.Height < 173)
{
MessageBox.Show("size invalid");
}**
else
{
pictureBox6.Image = new Bitmap(openfd.FileName);
}
}
You only need an image (bitmap, in this case), and notPictureBox
, which is a control rendering the image, a purely redundant control which, by some reasons, is a source of enormous confusions for many inquirers of this forum.
// ... var myBitmap = new Bitmap(openfd.FileName); int width = myBitmap.Width; int height = myBitmap.Height;
—SA
这篇关于如何验证图像和裁剪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!