views:

46

answers:

2

Hi there, I'm sure I've asked this question before but searching does nothing and I completely forgot how to do this.

I need a way to have a user choose a picture from their hard drive and load that picture to an Image class using the location.

I've done this in the past, but as I said I can't remember how I did it.

I know you can apply a file type filter to the OpenFileDialog.

private void LoadImageToMemory()
        {
            openFileDialog1.Filter = "JPEG | jpeg";
            openFileDialog1.ShowDialog();            
        }

Any guidance? Thank you!

+1  A: 

I figured it out!

In case anyone has the same question, this is how you do it.

private void LoadImageToMemory()
        {
            openFileDialog1.Filter = "png files (*.png)|*.png|jpg files (*.jpg)|*.jpg";
            openFileDialog1.Multiselect = false;
            openFileDialog1.InitialDirectory = @"C:\";
            openFileDialog1.Title = "Select a picture to transform.";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                txtFileName.Text = openFileDialog1.FileName;
            }            
        }
Sergio Tapia
A: 

Did you try reading the manual?

OpenFileDialog dlg = new OpenFileDialog();

// Filter by Word Documents OR Excel Worksheets OR PowerPoint Presentations 
//           OR Office Files 
//           OR All Files
dlg.Filter = "Word Documents|*.doc|Excel Worksheets|*.xls|PowerPoint Presentations|*.ppt"

. You really should be looking for such trivial info on MSDN or even Gooogle, instead of Stack Overflow. MSDN is your friend, THE programming bible for .Net developers.

Saajid Ismail
Why'd you vote me down? I gave you the answer, and some good advice! Guys help me out here...
Saajid Ismail
A "read the manual" argument can be applied to many, many questions on SO. I think every question on PHP I answered has already an answer in the manual. "Even Google" is an even worse argument. Obviously, 90% of questions can be removed from SO because they are already answered somewhere and can be found through Google.
MainMa
Exactly why I downvoted your answer.
Sergio Tapia
Just trying to guide the OP into making more use of MSDN and Google for simpler problems as this. No sarcasm or malice intended. Programmers need to learn 'how to learn', and it is up to other programmers to teach each other how to do this. And I also did still provide the answer.
Saajid Ismail