首页 > 解决方案 > 如何在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 那样的视频流。请帮忙,我希望你能理解我的问题

标签: c#wpfdensity-independent-pixel

解决方案


你没有说你从哪里实例化你的 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 设置为生成的图像。


推荐阅读