How to open an image file and display in picturebox?

  • Thread starter Thread starter Bradley1234
  • Start date Start date
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 )
 
Back
Top