如何在C#中检查图像属性 [英] how to check image property in C#

查看:61
本文介绍了如何在C#中检查图像属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查图像属性。我想只使用惰性图像,但是当我将任何exe文件或任何txt的扩展名更改为jpeg之后,当我插入它时,它被插入但是想要像这样停止。

视频情况相同...

请任何1帮我....

谢谢....

how to check image property. i want to inert only image but when i change extension of any exe file or any txt into jpeg after that when i insert it, it is inserted but want to stop like this.
same in case of video...
please any 1 help me....
thanks....

推荐答案

参见 http://stackoverflow.com/questions/58510/using-net-how-can-you-find-the-mime-type-of-a-file-based-on-the-file-signature [ ^ ]


krrazyumesh写道:
krrazyumesh wrote:

如果有人试图将txt文件或exe文件的扩展名更改为jpeg并上传它,那么它会抛出异常错误

if any one try to change the extension of txt file or exe file into jpeg and upload it, then it will throw an exception "error"

我会依赖文件名。如果您遇到此异常,只需向用户显示。



可能的用户将* .txt重命名为* .jpg的操作将是愚蠢的,以便将其复制例外。这并不意味着你不应该做好准备。您应该最终处理所有异常,但这不应该是特殊情况。一次处理所有其他异常。



-SA

I would rely on file name. If you got this exception, just show it to the user.

The possible user's action of renaming *.txt to *.jpg would be stupid enough to dub it "exceptional". It does not mean you should not be prepared to it. You should ultimately handle all exceptions, but this one should not be a special case. Handle it with all other exceptions at once.

—SA



我为你做了一个简单的工作。



在你的winform.button1上放置一个按钮和Pictuerbox,pictureBox1



在按钮中单击打开jpg文件并将其加载到图片框中。我已经使用了try catch如果所选文件是有效的jpeg然后显示在pictuer框中。如其他文件如texct或exe文件扩展名更改为jpg并且上传显示来自exceptaiton部分的错误消息。

请参阅buttonclikc代码在这里了解详情。

Hi,
I have made a simple Work out for you.

Place a Button and Pictuerbox on you winform.button1,pictureBox1

In Button click open the jpg file and load it in pictuer box. I have used try catch if the selected file is valid jpeg then display in pictuer box .if other file like texct or exe file extention change as jpg and upload display the error message from exceptaiton part.
see the buttonclikc code here for details.
private void button1_Click(object sender, EventArgs e)
      {
          string filename = "";
          OpenFileDialog open = new OpenFileDialog() { Filter = "Image Files|*.JPG;*.JPEG;" };
          if (open.ShowDialog() == DialogResult.OK)
          {
              filename = open.FileName;
          }
          if (filename != "")
          {
              string image = filename;
              try
              {
                  Bitmap bmp = new Bitmap(image);


              pictureBox1.Image = bmp;//add this line
              FileStream fs = new FileStream(image, FileMode.Open, FileAccess.Read);
              byte[] bimage = new byte[fs.Length];
              fs.Read(bimage, 0, Convert.ToInt32(fs.Length));
              fs.Close();
              byte[] Photo = bimage;
                  }
               catch (Exception ex)
              {
                  MessageBox.Show("Select the valid file");
              }

          }
      }


这篇关于如何在C#中检查图像属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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