Connecting Tech Pros Worldwide Forums | Help | Site Map

How to open an image file and display in picturebox?

Bradley1234
Guest
 
Posts: n/a
#1: Nov 16 '05
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 )



CiccioPalla
Guest
 
Posts: n/a
#2: Nov 16 '05

re: How to open an image file and display in picturebox?


Image img = Image.FromFile(filename);

pictureBox1.Image = img;

"Bradley1234" <someone@yahoo.com> ha scritto nel messaggio
news:wjvpd.9717$5v1.749@trnddc06...[color=blue]
> 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[/color]
on[color=blue]
> 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 )
>
>[/color]


Bradley1234
Guest
 
Posts: n/a
#3: Nov 16 '05

re: How to open an image file and display in picturebox?


Thanks, that worked!



"CiccioPalla" <CiccioPalla@NOSPAMxiansoft.net> wrote in message
news:OflzXa10EHA.3092@TK2MSFTNGP10.phx.gbl...[color=blue]
> Image img = Image.FromFile(filename);
>
> pictureBox1.Image = img;
>
> "Bradley1234" <someone@yahoo.com> ha scritto nel messaggio
> news:wjvpd.9717$5v1.749@trnddc06...[color=green]
> > Seems simple but Im missing something. In a C# form Ive got a[/color][/color]
picturebox[color=blue][color=green]
> > and a button
> >
> > I have the File Open dialog linked to the button, but Im drawing a blank[/color]
> on[color=green]
> > 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[/color][/color]
system.drawing.image[color=blue][color=green]
> >
> >
> >
> > }
> >
> > catch( Exception ex )
> >
> >[/color]
>
>[/color]


Closed Thread