Dave van Staden
Dave van Staden

Reputation: 11

How to load a image into a picture box?

I Am programming in C# and I Already have it that I can select my files from my phone with this text:

private void Button_Click_2(object sender, RoutedEventArgs e)
{
    var FileOpenPicker = new Windows.Storage.Pickers.FileOpenPicker();
    FileOpenPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.List;
    FileOpenPicker.FileTypeFilter.Add(".jpg");
    FileOpenPicker.FileTypeFilter.Add(".jpeg");
    FileOpenPicker.FileTypeFilter.Add(".png");
    FileOpenPicker.PickSingleFileAndContinue();

How can I let the picture popup in the picturebox?

Upvotes: 0

Views: 1305

Answers (1)

Slashy
Slashy

Reputation: 1881

Use a FileDialog and load a bitmap from the selected path:

   using (OpenFileDialog dlg = new OpenFileDialog())
{
    dlg.Title = "Open Image";
    dlg.Filter = "bmp files (*.bmp)|*.bmp";

    if (dlg.ShowDialog() == DialogResult.OK)
    {
        // Create a new Bitmap object from the picture file on disk,
        // and assign that to the PictureBox.Image property
        PictureBox1.Image = new Bitmap(dlg.FileName);
    }
}

Upvotes: 1

Related Questions