I have a running program in Winforms. The Winforms able to display the stream from CCTV. Now, I want to migrate to WPF. I don't want to use any Winforms host in my WPF. Below are the original code from Winforms:
IntPtr LoginID = IntPtr.Zero;
int ChannelID = 1;
PictureBox pictureBox;
IntPtr RealPayID = NETClient.RealPlay(LoginID, ChannelID, pictureBox.Handle, EM_RealPlayType.Realplay);
I have several method I try but I cannot view it on the WPF. How do I get the value from the MainCamera_IntPtr and pass it to image source?
What I have tried:
This is what I got so far. But I'm clueless how do I continue to pass the stream to BitmapSource so I can display on Image.Source
IntPtr MainCamera_IntPtr = IntPtr.Zero;
int RenderWidth = 900;
int RenderHeight = 550;
int stride = ((RenderWidth * 32 + 31) & ~31) / 8;
System.Drawing.Imaging.PixelFormat pixelformat = System.Drawing.Imaging.PixelFormat.Format32bppRgb;
MainCamera_Bitmap = new System.Drawing.Bitmap(RenderWidth, RenderHeight, stride, pixelformat, MainCamera_IntPtr);
IntPtr hbitmap = MainCamera_Bitmap.GetHbitmap();
var handle = new Utility.SafeHBitmapHandle(hbitmap, true);
using (handle)
{
MainCamera_BitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(handle.DangerousGetHandle(), IntPtr.Zero, System.Windows.Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
}
IntPtr RealPayID = NetSDK.NETClient.RealPlay(LoginID, ChannelID, MainCamera_IntPtr, NetSDK.EM_RealPlayType.Realplay);