将图像文件打开到图片框中,使其成为位图
我希望能够在图片框中打开 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您希望将倒数第二行的
ofd2
替换为openFileDialog1
。You want to replace
ofd2
withopenFileDialog1
on the penultimate line.