1

我正在尝试将多个BitmapSource图像从 png 文件中导出。这是我的代码:

线程调用:

var exportImagesThread = new Thread(ExportRangeOfImages);
exportImagesThread.Start();

功能:

private void ExportRangeOfImages()
{
     for (var currentFrame = exportFromFrame; currentFrame <= exportToFrame; currentFrame++)
     {
            var currentImage = Application.Current.Dispatcher.Invoke(() => (currentStream.Children[0] as Image).Source);
            var pngBitmapEncoder = new PngBitmapEncoder();
            var bitmapFrame = BitmapFrame.Create((BitmapSource) currentImage);

            Application.Current.Dispatcher.Invoke(() => pngBitmapEncoder.Frames.Add(bitmapFrame));
            var a = new FileStream(updatedDir + sequenceFile + "_" + frameNumber + ".png", FileMode.Create);
            pngBitmapEncoder.Save(a);
     }
}

这样做时,我会Additional information: The calling thread cannot access this object because a different thread owns it.在线收到:var bitmapFrame = BitmapFrame.Create((BitmapSource) currentImage);

我错过了什么?

4

0 回答 0