【问题标题】:Refresh image using saved paths from database使用数据库中保存的路径刷新图像
【发布时间】:2013-06-03 09:50:57
【问题描述】:

嗨。这是Visual Studio 2010 中的C#。我使用以下方法上传了图像路径。路径已成功存储在数据库中,并显示上传的图像。然而,尽管我浏览了其他记录,但上传的图像仍然显示。不检索其他图像,仅保留上传的图像。保存后我尝试再次重新填充数据集,但它给出了错误:“URI 为空”。除了路径(photo_text.Text)的图片外,其他文本字段刷新成功。

private void uploadPhoto_Click(object sender, RoutedEventArgs e)
{
    Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
    ofd.FileName = ".jpg";
    ofd.InitialDirectory = "C:\\Users\\Public\\Pictures";
    ofd.Title = "Select passport photo to upload";
    ofd.Filter = "Image Files (*.JPG)|*.jpg|All files (*.*)|*.*";

    if (ofd.ShowDialog() == true)
    {
        pixx.Source = new BitmapImage(new Uri(ofd.FileName));
        photo_text.Text = ofd.FileName;
    }
}

第二种方法:

if (studentsDataSetstudentTableAdapter.Update(studentsDataSet.student) > 0)
{
    MessageBox.Show("Your data has been saved!", "DATA STATUS", MessageBoxButton.OK, MessageBoxImage.Information);
    studentsDataSetstudentTableAdapter.Fill(studentsDataSet.student);
    pixx.Source = new BitmapImage(new Uri(photo_text.Text));
}

【问题讨论】:

    标签: wpf image dataset refresh


    【解决方案1】:

    在有源绑定到有选项的数据的数据的图像的图像属性中,'mode'应该设置为“TwoWay”和'UpdateSourceTrigger'为“PropertyChanged” 每次翻阅记录时,图像都会改变!

    【讨论】:

      【解决方案2】:

      我也有同样的问题。当我加载图像时出现并且写得很好。但是当我站在另一个登记处时,每个人的形象都是一样的。 在 XAML 中,我指示 Robert Omete,但当我设置 Mode = TwoWay 或 OneWayToSource 时,没有图像出现空白。

      加载图像代码:

          private void BtnCargarFoto_Click(object sender, RoutedEventArgs e)
          {
              OpenFileDialog OD = new OpenFileDialog();
              OD.Filter = "jpg(*.jpg)|*.jpg|png(*.png)|*.png|gif(*.gif)|*.gif|bmp(*.bmp)|*.bmp|All Files(*.*)|*.*";
              if (OD.ShowDialog() == true)
              {
                  using (Stream stream = OD.OpenFile())
                  {
                      //bitCoder = BitmapDecoder.Create(stream, BitmapCreateOptions.PreservePixelFormat,
                      //    BitmapCacheOption.OnLoad);
                      bitCoder = BitmapDecoder.Create(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
                      ImgFoto.Source = bitCoder.Frames[0];
                  }
                  System.IO.FileStream fs = new System.IO.FileStream(OD.FileName, System.IO.FileMode.Open);
                  foto = new byte[Convert.ToInt32(fs.Length.ToString())];
                  fs.Read(foto, 0, foto.Length);
              }
          }
      

      XAML:

                  <Image x:Name="ImgFoto" Source="{Binding Foto, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"   Stretch="Fill" HorizontalAlignment="Left" 
                         Height="127" Margin="38,29,0,0" VerticalAlignment="Top" Width="176">
                  </Image>
      

      【讨论】:

        猜你喜欢
        • 2015-07-14
        • 1970-01-01
        • 1970-01-01
        • 2012-01-27
        • 2019-04-02
        • 2021-02-07
        • 1970-01-01
        • 2012-07-26
        • 2015-10-12
        相关资源
        最近更新 更多