このコードでこの例外が発生します。 修正方法?WPF - 別のスレッドから "System.Windows.Controls.Image"を更新します
Excepton:
異なるスレッドが それを所有しているので、呼び出し元のスレッドがこの オブジェクトにアクセスすることはできません。
コード:
void CamProc_NewTargetPosition(IntPoint Center, System.Drawing.Bitmap image)
{
IntPtr hBitMap = image.GetHbitmap();
BitmapSource bmaps = Imaging.CreateBitmapSourceFromHBitmap(hBitMap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
Dispatcher.BeginInvoke((Action)(() =>
{
labelX.Content = String.Format("X: {0}", Center.X); //OK Working
labelY.Content = String.Format("Y: {0}", Center.Y); //OK Working
pictureBoxMain.Source = bmaps; // THERE IS EXCEPTON
}), DispatcherPriority.Render, null);
}
pictureBoxMainがSystem.Windows.Controls.Imageです。
あなたはそれがどのスレッドからアクセスできるようにしたBitmapSourceを凍結することができます