简体   繁体   中英

Open a Image File into a Picturebox making it a Bitmap

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

您想在倒数第二行上用openFileDialog1替换ofd2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM