Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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; // This is the element on the winforms screen.

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);
Posted
Comments
RickZeeland 13-Sep-22 2:13am    
Are you using the Hikvision SDK? then it might be better to ask Hikvision support for more information.
Luiey Ichigo 13-Sep-22 2:16am    
No, I'm using General Net SDK for PTZ Camera by Dahua Technology. All their samples are using Winforms.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900