开发者

Open a Image File into a Picturebox making it a Bitmap

开发者 https://www.devze.com 2023-01-31 06:57 出处:网络
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 m

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 pr开发者_StackOverflowogram 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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消