2013-06-03 8 views
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)); 
} 

답변

0

은 '모드' '로 설정해야 TwoWay "및"UpdateSourceTrigger '를 "PropertyChanged" 기록을 넘길 때마다 이미지가 변경됩니다!

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> 
관련 문제