Closed futureflsl closed 5 years ago
I'm sorry but I don't really understand what you want to do. I tried the following code and it works.
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using OpenCvSharp;
namespace OpenCvSharpSamples
{
class Program
{
[DllImport("user32.dll", EntryPoint = "GetParent", SetLastError = true)]
public static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("user32.dll", EntryPoint = "SetParent")]
public static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
//[DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Auto)]
//public void FillControl(PictureBox pic, string title);
[STAThread]
static void Main(string[] args)
{
using (var bitmap = new Bitmap("lenna.png"))
using (var mat = new Mat("a.jpg"))
{
var pictureBox = new PictureBox();
pictureBox.Image = bitmap;
pictureBox.ClientSize = new System.Drawing.Size(bitmap.Width, bitmap.Height);
var form = new Form();
form.Text = "WinForm";
form.ClientSize = new System.Drawing.Size(800, 600);
form.Controls.Add(pictureBox);
const string title = "Main Window";
Cv2.NamedWindow(title, WindowMode.AutoSize);
Cv2.ImShow(title, mat);
Cv2.ResizeWindow(title, pictureBox.Width, pictureBox.Height);
IntPtr hWnd = FindWindow("Main HighGUI class", title);
SetParent(hWnd, pictureBox.Handle);
Application.Run(form);
}
}
}
}
I know in MFC,we can use the code make imshow's window be the child of one picture control void FillPicCtrl(int nID,CString strTitle)
now,I try to use the same method in opencvsharp
But It doesn't Work,Someone Can solve this problem?