簡體   English   中英

如何將圖片加載到圖片框中?

[英]How to load a image into a picture box?

我正在用C#編程,並且已經有了可以從手機中選擇以下文本的文件:

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();

如何讓圖片在圖片框中彈出?

使用FileDialog並從所選路徑加載位圖:

   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);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM