0

你好。这是C#Visual Studio 2010. 我使用以下方法上传了图像路径。路径已成功存储在数据库中,并显示上传的图像。然而,尽管我浏览了其他记录,但上传的图像仍然显示。不检索其他图像,仅保留上传的图像。保存后我尝试再次重新填充数据集,但它给出了错误:“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));
}
4

2 回答 2

0

在图像的图像属性中,从有选项的数据中,源绑定到数据的数据中,“模式”应设置为“ TwoWay ”,“UpdateSourceTrigger”应设置为“ PropertyChanged ”,每次您使用时图像都会更改翻阅记录!

于 2013-06-03T19:25:24.697 回答
0

我也有同样的问题。当我加载图像时出现并且写得很好。但是当我站在另一个登记处时,每个人的形象都是一样的。在 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>
于 2014-10-29T18:53:15.143 回答