如何验证图像和裁剪 [英] How to validate image and crop

查看:97
本文介绍了如何验证图像和裁剪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想验证图片,验证其高度和宽度 用户尝试上传时,如果使用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 not PictureBox, 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆