I start with WPF and try to make the home project familiar with technology. I have a simple form in which the user selects an image file, then I show the EXIF ββdata along with a thumbnail of the image. This works fine, but when I select a RAW image file (~ 9 MB), there may be a slight delay while the thumb is loading, so I decided to use BackgroundWorker to decode the image and the user can view the EXIF ββdata, then when the image is decoded, it is displayed .
The BitmapSource object is declared in the BackgroundWorkers DoWork method:
worker.DoWork += delegate(object s, DoWorkEventArgs args)
{
string filePath = args.Argument as string;
BitmapDecoder bmpDecoder = BitmapDecoder.Create(new Uri(filePath), BitmapCreateOptions.None, BitmapCacheOption.None);
BitmapSource bmpSource = bmpDecoder.Frames[0];
bmpSource.Freeze();
args.Result = bmpSource;
};
, , - Image RunWorkerCompleted. , .
worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
{
imgThumb.Source = args.Result as BitmapSource;
};
imgThumb.Dispatcher.BeginInvoke() , , , args.Result , imgThumb? ?
, ( , , ).
imgThumb.Dispatcher.Invoke(new Action<BitmapSource>(
delegate(BitmapSource src)
{
imgThumb.Source = src;
}
), bmpSource);
.
DoWork BitmapCreateOptions.None, .DelayCreation, RAW ( Canon.CR2 - , ), jpg. Canon Codec, RAW ?
, . ( HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))