WPF BackgroundWorker를 사용하여 축소판을 만듭니다. 내 작업자 기능과 같이 보인다 :다른 스레드의 BitmapFrame
기능이 시작됩니다 "완료"를 BackgroundWorker에, 내가 VS2008의 출력 창에서 볼 수 있습니다 전에이 함수는 예외가 생성됩니다, 완료하고private void work(object sender, DoWorkEventArgs e)
{
try
{
var paths = e.Argument as string[];
var boxList = new List<BoxItem>();
foreach (string path in paths)
{
if (!string.IsNullOrEmpty(path))
{
FileInfo info = new FileInfo(path);
if (info.Exists && info.Length > 0)
{
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.DecodePixelWidth = 200;
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.UriSource = new Uri(info.FullName);
bi.EndInit();
var item = new BoxItem();
item.FilePath = path;
MemoryStream ms = new MemoryStream();
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bi));
encoder.Save(ms);
item.ThumbNail = ms.ToArray();
ms.Close();
boxList.Add(item);
}
}
}
e.Result = boxList;
}
catch (Exception ex)
{
//nerver comes here
}
}
. 예외의 수는 생성
A first chance exception of type 'System.NotSupportedException' occurred in PresentationCore.dll
축소판의 수를 생성 할 같다 : 것 같습니다. "시행 착오"나는에 문제를 격리 한 방법을 사용
: BitmapFrame.Create (BI)
그 라인을 제거는 (내 기능 쓸모하게)도 예외를 제거합니다.
나는 이것에 대한 설명을 찾지 못했거나 백그라운드 스레드에서 축소판을 만드는 더 좋은 방법을 찾지 못했습니다.
그런 식으로 말하면, 당신은 요점이 있다고 생각합니다. ProgressChanged 이벤트를 사용하여 ,,, 어떻게 작업자 스레드로 값을 다시 보냅니 까 ??? –