c# - 如何在c#中调用图像变量到另一个调用
问题描述
我有两个类 Mainwindow 和 Mini_Screen 派生自 Window 类。我想将图像变量访问到另一个类以及视频流的方式。这里是代码
public partial class MainWindow : Window
{
public static Image<Bgr, Byte> contour_Frame;
public void Bu_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
FinalFrame = new VideoCaptureDevice(CaptureDevice[Camera_ComboBox.SelectedIndex].MonikerString);
FinalFrame.NewFrame += new NewFrameEventHandler(FinalFrame_NewFrame);
FinalFrame.Start();
}
void FinalFrame_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Imgbox1.Image = skin;
}
}
二等
public partial class Mini_Screen : Window
{
public Mini_Screen()
{ InitializeComponent();
Imgbox2.Image = MainWindow.emgu_img;
}
}
我这样做了,但我只在 Imgbox2 中看到一个捕获图像。我想要像 imgbox1 那样的视频流。请帮忙,我希望你能理解我的问题
解决方案
你没有说你从哪里实例化你的 2 个屏幕,但因为它是 MainWindow,我假设 Mini_Screen 是在那里实例化的。
使用属性很容易实现。
这是您调整后的 MainWindow
public partial class MainWindow : Window
{
public static Image<Bgr, Byte> contour_Frame;
public Mini_Screen subwindow;
public void MainWindow_Load(object sender, EventArgs e)
{
subwindow = new MiniScreen();
subwindow.Show();
}
public void Bu_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
FinalFrame = new VideoCaptureDevice(CaptureDevice[Camera_ComboBox.SelectedIndex].MonikerString);
FinalFrame.NewFrame += new NewFrameEventHandler(FinalFrame_NewFrame);
FinalFrame.Start();
}
void FinalFrame_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Imgbox1.Image = skin;
subwindow.DisplayImage = skin;
}
}
然后你调整的 Mini_Screen
public partial class Mini_Screen : Window
{
public Image DisplayImage
{
set
{
Imgbox2.Image = value;
}
}
public Mini_Screen()
{
InitializeComponent();
}
}
现在,当 NewFrame 事件触发时,它将 DisplayImage 属性设置为您的新图像,进而将 ImgBox2.Image 设置为生成的图像。
推荐阅读
- apache-spark - 火花结构化流式镶木地板覆盖
- angularjs - 无法加载 HTML 页面
- node-oracledb - 动态地将变量传入 where 语句
- excel - 如何命令 vba 从特定单元格开始粘贴?
- reactjs - React Native 样板模板
- mysql - MySQL:计算按列分组的值的中位数
- reactjs - 如何使条码扫描器的中心透明?
- reactjs - 如何重用 react-router 的 useHistory 的 jest mock
- xml - 使用 XSLT 转换 nxm XML 表
- javascript - Webdriverio如何做一个TAB键动作