How to Load an Image from the Local Directory into the PictureBox in C#
Submitted by janobe on Friday, November 9, 2018 - 22:28.
      
            In this tutorial, I will teach you how to load an image from the local directory into the picturebox in c#. In here , I used the openfiledialog to access the local directory. In this way, I can get an image and put it into the picturebox.
 
 For any questions about this article. You can contact me @
Email – [email protected]
Mobile No. – 09305235027 – TNT
Or feel free to comment below.
For any questions about this article. You can contact me @
Email – [email protected]
Mobile No. – 09305235027 – TNT
Or feel free to comment below.
      
            Creating Application
Step 1
Open Microsoft Visual Studio 2015 and create a new windows form application in c#. 
Step 2
Add a PictureBox ,OpenFileDialog and Button into the form. 
Step 3
Double click the button to fire theclick event handler of it and do the following code to get an image from the local directory and load it into the picturebox. 
- //filter the file you want to get
- openFileDialog1.Filter = "img (*.jpg)|*.jpg|All files (*.*)|*.*";
- //set an intial directory
- openFileDialog1.InitialDirectory = @"C:\";
- //Put the title in the dialog box
- openFileDialog1.Title = "Please select an image.";
- //validating result
- if (openFileDialog1.ShowDialog() == DialogResult.OK)
- {
- //set the image to be stretch
- pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
- //load the image in the picture box
- pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
- }
 
              