WPF/BackgroundWorker and BitmapSource problem -
I am the first with WPF and am trying to get a home project to become familiar with technology. I have a simple form where the user selects an image file, then I will display the EXIF data with the thumbnail of the image. I'm working fine, but when I get a raw image file (~ 9 MB) If I select, then there may be a slight delay in the loading of thumb, so I think I can use the background player to decode the image and the user can see the EXIF data, then when the image is decoded , It is displayed.
> BitmapSource object has been declared in the Background Workers Druver method:
worker.DoWork + = delegate (Objects, Duplicate Avent ARG) {String filePath = args.Argument As a string; Bitmapcodecoder BMPDcoder = BitMapDiCoder Create (new yuri (bitpip), bitmapcreate option. Non, bitmap options. Bitmapsource bmpSource = bmpDecoder.Frames [0]; BmpSource.Freeze (); // As suggested by Paul Bates. Result = BMPSOS; };
The problem I am running is when I try to set the source of my image control in the included RunWorker method, I get an error because the object is owned by another thread. .
worker.RunWorkerCompleted + = Representative (Objects, Run Worker's Completed Avenues Args) {imgThumb.Source = args.Result Bitmapsource; };
I tried to use the imgThumb.Dispatcher.BeginInvoke ()
method to set the source but it does not work either, I think Because this Args.Result
is owned by that other thread, and is not imgThumb
? How can I score this goal?
It may be that I was misinterpreting my display (with the following memory, everything I did was removed.)
imgThumb Dispatcher.Invoke (new Action & lt; Bitmaposource & gt; (Representative (bitmap site source) {imgThumb.Source = src;}), bmpSource);
Any suggestions or ideas are welcome.
Update
To change your Duplication method to use the Bitmapcreate option. Compared to .DelayCreation But now I get the following error when loading the RAW files (Canon .CR2 files I have tested all to date till now), Code works fine for JPG. Can I have a problem with Canon Codec installed to allow RAW files to be displayed?
The application is called an interface that was martial for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))
call freeze () on bitmapsource and You will not have this problem (freezing gets rid of threading restrictions, but the object makes it irreversible)
Comments
Post a Comment