How to open an image file and display in picturebox?

B

Bradley1234

Seems simple but Im missing something. In a C# form Ive got a picturebox
and a button

I have the File Open dialog linked to the button, but Im drawing a blank on
how to take the stream and push the thing onto the picturebox.

Here is the code, tia

OpenFileDialog fileChooser = new OpenFileDialog();

DialogResult result = fileChooser.ShowDialog();

string filename; //name of file containint data

if (result == DialogResult.Cancel)

return;

filename = fileChooser.FileName;

if (filename == "" || filename == null)

MessageBox.Show("Hey, thats a not a what I want a see", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

else

{

input = new FileStream(filename, FileMode.Open, FileAccess.Read);

}

try {

pictureBox1.Image = input; //NO WAY, IT HAS AN ERROR THAT SAYS

cannot implicity convert type system.io.filestream to system.drawing.image



}

catch( Exception ex )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top