GetPixel API 问题 C#编程

洗澡卡 洗澡卡 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我在窗体上创建了一个PictrueBox控件,并将PictrueBox的背景颜色设为红色。想在鼠标按下时,获取当前坐标的颜色,查了很多资料也不知道怎么解决,求解决,本人初次使用C#调用API。在此谢过。
以下是我的声明及使用
using System.Runtime.InteropServices;
[DllImport("gdi32.dll")]
public static extern System.UInt32 GetPixel(IntPtr hdc, int xPos, int yPos);
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
Graphics gra = Graphics.FromHwnd(((PictureBox)sender).Handle);
IntPtr hdc = gra.GetHdc();
label5.BackColor = Color.FromArgb(Convert.ToInt32(GetPixel(hdc, e.X, e.Y)));
}
...全文

相关推荐

评论 10
收藏 已收藏
分享
返回顶部
洗澡卡
C# 111,129 成员 642,540 内容