I'm not sure what to do! I'm trying to run OpenCV in a background thread and have it send the image to the dispatcher. Here's a (distilled) version of the code:
private Thread _thread
private void WindowLoaded(){
_thread = new Thread(new ThreadStart(OpenCV)); //Run in seperate thread
_thread.Start();
}
private void OpenCV(){
//CV Image Capturing and parsing etc - works fine!
//...
//Problems begin
System.Drawing.Bitmap bm = BitmapConverter.ToBitmap(gray); //Get a usable image from CV
bm.SetResolution(640.0f, 480.0f); //Change its resolution
Dispatcher.BeginInvoke(new Action(() => { //Invoke this to be run in main thread
updateImage(bm); //Code that updates UI
}));
}
private void updateImage(System.Drawing.Bitmap img) {
ImageSourceConverter c = new ImageSourceConverter();
//Console.WriteLine(c == null); //No success in testing for nulls!
MyImage.Source = (ImageSource)c.ConvertFrom(img); //The problem is here
}
In the last line of updateImage
The error in the title happens. I have seen many other people exqperiencing very similar problems, but none of their solutions seem to work.
MyImage is not null when the exception is called, nor is c or img. However, MyImage.Source is.