我有一个有两个字段和一些绘图方法的类:
public class DrawingTool
{
private readonly DrawingGroup _drawingGroup;
private DrawingImage _imageSource;
public DrawingTool()
{
_drawingGroup = new DrawingGroup();
_imageSource = new DrawingImage(_drawingGroup);
}
public DrawingImage GetImageSource()
{
return _imageSource;
}
public void DrawSomething()
{
using (DrawingContext dc = _drawingGroup.Open()) // HERE'S AN ERROR - _drawing group is being used by another thread (InvalidOperationException)
{
// draw something here
}
}
}
这是一个WPF
项目,所以我也有一个Image
:
<Image x:Name="MyImage" Width="320" Height="240"></Image>
我设置了来源:
_drawingTool = new DrawingTool();
Dispatcher.Invoke(() => MyImage.Source = _drawingTool.GetImageSource());
_device.FrameReady += (sender, args) => Dispatcher.Invoke(() =>
{
_drawingTool.DrawSomething();
});
我从评论中得到一个错误......我试图调用DrawSomething()
方法并CheckAccess()
在_drawingGroup
内部使用DrawSomething()
- 没有帮助。如何使其工作成为可能?提前感谢您的帮助!
[编辑 1.]
也许我应该使用不同于DrawingGroup
?
[编辑 2.]
没人知道吗?:(