
byte[] ImgBuf =new ImgBuf [9285763+80];
int getc = XMSDKH264_PLAY_CatchPicBuf(1,ImgBuf,9285763+80,ref ImgWidth, ref ImgHeight, 0);
可以利用原生态的API方法来实现,通过GetDC获取屏幕DC,然后通过GetPixel获取点的颜色。代码如下:
/// <summary>/// </summary>
/// <param name="hwnd">将获取其设备场景的窗口的句柄。若为0,则要获取整个屏幕的DC</param>
/// <returns>指定窗口的设备场景句柄,出错则为0</returns>
[DllImport("user32dll")]
public static extern IntPtr GetDC(IntPtr hwnd);
/// <summary>
/// 释放由调用GetDC函数获取的指定设备场景
/// </summary>
/// <param name="hwnd">要释放的设备场景相关的窗口句柄</param>
/// <param name="hdc">要释放的设备场景句柄</param>
/// <returns>执行成功为1,否则为0</returns>
[DllImport("user32dll")]
public static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc);
/// <summary>
/// 在指定的设备场景中取得一个像素的RGB值
/// </summary>
/// <param name="hdc">一个设备场景的句柄</param>
/// <param name="nXPos">逻辑坐标中要检查的横坐标</param>
/// <param name="nYPos">逻辑坐标中要检查的纵坐标</param>
/// <returns>指定点的颜色</returns>
[DllImport("gdi32dll")]
public static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos);
使用:
public Color GetColor(int x, int y)
{
IntPtr hdc = GetDC(IntPtrZero); uint pixel = GetPixel(hdc, x, y);
ReleaseDC(IntPtrZero, hdc);
Color color = ColorFromArgb((int)(pixel & 0x000000FF), (int)(pixel & 0x0000FF00) >> 8, (int)(pixel & 0x00FF0000) >> 16);
return color;
}
以上就是关于c#调用DLL中char*(图像),使用intptr但是没有返回值,且调用至函数运行时 exe停止运行全部的内容,包括:c#调用DLL中char*(图像),使用intptr但是没有返回值,且调用至函数运行时 exe停止运行、C#获取屏幕指定像素颜色值、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)