将图像文件打开到图片框中,使其成为位图

发布于 2024-10-07 23:33:56 字数 559 浏览 1 评论 0原文

我希望能够在图片框中打开 .jpg、.gif 或 .bmp 并将其设为位图,以便我可以在其上绘图,但目前它会出现“参数无效”错误我运行我的程序,然后尝试将这些图像文件之一加载到我的图片框中。 这是我当前的代码:

openFileDialog1.InitialDirectory = @"N:\My Documents\My Pictures";
openFileDialog1.Filter = "JPEG Compressed Image (*.jpg|*.jpg" + "|GIF Image(*.gif|*.gif" + "|Bitmap Image(*.bmp|*.bmp";
openFileDialog1.Multiselect = true;
openFileDialog1.FilterIndex = 1;         
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
    capturebox.BackgroundImage = new Bitmap(ofd2.FileName);
}

我不知道为什么会发生这种情况,请帮忙。

谢谢

I want to be able to open either a .jpg, .gif or .bmp into a picturebox and make it a bitmap so i can draw on it, but at the moment it comes up with an error of 'Parameter is not valid' when i run my program and then try to load one of these image files into my picturebox.
This is my current code:

openFileDialog1.InitialDirectory = @"N:\My Documents\My Pictures";
openFileDialog1.Filter = "JPEG Compressed Image (*.jpg|*.jpg" + "|GIF Image(*.gif|*.gif" + "|Bitmap Image(*.bmp|*.bmp";
openFileDialog1.Multiselect = true;
openFileDialog1.FilterIndex = 1;         
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
    capturebox.BackgroundImage = new Bitmap(ofd2.FileName);
}

I don't know why this occurs, please help.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

○闲身 2024-10-14 23:33:56

您希望将倒数第二行的 ofd2 替换为 openFileDialog1

You want to replace ofd2 with openFileDialog1 on the penultimate line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文