【问题标题】:Image.FromFile and picturebox won't display image from computerImage.FromFile 和picturebox 不会显示来自计算机的图像
【发布时间】:2014-03-29 05:05:18
【问题描述】:

我正在使用 Winforms 并且有一个图片框。当用户单击它时,我想从我的计算机加载图像。但它不起作用。任何想法为什么?

 private void pictureBox1_Click(object sender, EventArgs e)
 {
     pictureBox1.Image = Image.FromFile("C:/wamp/www/cyber.jpeg");
     pictureBox1.Image = new Bitmap(@"C:\wamp\www\cyber.jpeg");
 }

如果我单击它,我会收到错误“FileNotFoundException was unhandled”。如果我删除 Image.FromFile 并改用位图,则会收到错误“参数无效”

【问题讨论】:

  • 你有没有文件扩展名.jpeg.jpg检查。
  • 那么,很明显,您的文件名和/或文件路径是错误的!
  • 我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。

标签: c# winforms


【解决方案1】:

试试这个

  pictureBox1.Image = Image.FromFile(@"C:\wamp\www\cyber.jpeg");

【讨论】:

    【解决方案2】:

    假设你的文件路径是正确的,我认为你有.jpg作为你的图像的扩展名,但你试图用扩展名.jpeg访问

    试试这个:

    pictureBox1.Image = Image.FromFile("C:/wamp/www/cyber.jpg");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-27
      • 2014-04-14
      • 1970-01-01
      相关资源
      最近更新 更多