I get this error. Here is the code:
Image image;
BitmapImage BmpImg;
MemoryStream ms;
public void Convert()
{
ms = new MemoryStr
BmpImg
is created on background thread. You cannot bind to Image Source DP
object which is created on thread other than UI thread.
Since you are using Dispatcher
, i assume you now how to delegate stuff on UI thread.
So all you need to do is put the creation of BmpImg
on UI thread as well via Dispatcher.
You can get UI dispatcher like this as well - App.Current.Dispatcher
.
OR
As @Clemens suggested in comments, if you call Freeze()
on BitmapImage instance, you can access it across threads.
BmpImg.Freeze()