2013-05-07 4 views
1

이미지 경로 (ObservableCollection을 소스로 함)가있는 목록 상자가 있고 IValueConverter가이를 이미지 축소판으로 바꾸고 있습니다. "다른 프로세스에서 사용 중이기 때문에 프로세스가 파일을 액세스 할 수 없습니다 '\ test.jpg를 C'."IValueConverter 블록은 삭제를 방지합니다.

: 그 어떤 파일을 삭제하려고하면

, 나는 오류

public class UriToBitmapConverter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
    try 
    { 
     BitmapFrame bit = BitmapFrame.Create(new Uri(value.ToString()), BitmapCreateOptions.DelayCreation, BitmapCacheOption.OnDemand); 
     if (bit.Thumbnail != null) 
     { 
     return bit.Thumbnail; 
     } 
     else 
     { 
      BitmapImage bi = new BitmapImage(); 
      bi.BeginInit(); 
      bi.DecodePixelWidth = 200;      
      bi.UriSource = new Uri(value.ToString()); 
      bi.CacheOption = BitmapCacheOption.OnLoad; 
      bi.EndInit(); 
      return bi; 
     } 
     } 
    catch 
    { 
     return null; 
    } 
    } 

이미지를 강제로 해제하거나 파일을 강제로 삭제 하시겠습니까? 고맙습니다.

답변

2

아마도 FileStreamStreamSource을 사용할 수 있습니다.

Set the CacheOption property to BitmapCacheOption.OnLoad if you wish to close the stream after the BitmapImage is created. The default OnDemand cache option retains access to the stream until the bitmap is needed, and cleanup is handled by the garbage collector.

+0

문제가 해결되었습니다. 당신이 말했듯 : FileStream fileStream = 새로운 FileStream (value.ToString(), FileMode.Open, FileAccess.Read); ... img.StreamSource = fileStream; 고마워요! – Daniel

+0

환영합니다. 도움을 주셔서 감사합니다. –

+0

사실, 사례 이미지의 첫 번째 작품은 이미 미리보기 이미지가 있지만 두 번째 부분은 아니며 지금은 이미지가 없습니다. 내가 휴식을 취하면 나는 볼 수있다. '(img.StreamSource) .ReadTimeout'은 'System.InvalidOperationException'형식의 예외를 던졌습니다. img.StreamSource = fileStream; – Daniel