繁体   English   中英

c# 中的颜色范围轨迹栏?

[英]Colour range trackbar in c#?

我想制作一个具有图像颜色的范围跟踪栏(每种颜色都有一个关联的数值),因此当您移动跟踪栏的拇指时,您只会在图像中显示两个拇指之间的颜色范围。 我已经寻找了一些可能有用的跟踪栏,但我没有找到任何显示图像颜色的跟踪栏。 有任何想法吗? 谢谢你。

以下片段可能会启发您进行自己的开发:

private void SetCurrentColor(int x, int y)
{
    if (!busy)
    {
        busy = true;
        Point location = new Point(x, y);

        color = GetColorAt(location);
        int rgb = color.ToArgb() & 0x00FFFFFF;
        lblRgbInt.Text = "#" + rgb.ToString("X");
        lblRgb.Text = $"{color.R},{color.G},{color.B}";
        busy = false;
    }
}

private void HookManager_MouseMove(object sender, MouseEventArgs e)
{
    SetCurrentColor(e.X, e.Y);
}

Bitmap screenPixel = new Bitmap(1, 1, PixelFormat.Format32bppArgb);

public Color GetColorAt(Point location)
{
    using (Graphics gdest = Graphics.FromImage(screenPixel))
    {
        using (Graphics gsrc = Graphics.FromHwnd(IntPtr.Zero))
        {
            IntPtr hSrcDC = gsrc.GetHdc();
            IntPtr hDC = gdest.GetHdc();
            int retval = BitBlt(hDC, 0, 0, 1, 1, hSrcDC, location.X, location.Y, (int)CopyPixelOperation.SourceCopy);
            gdest.ReleaseHdc();
            gsrc.ReleaseHdc();
        }
    }

    return screenPixel.GetPixel(0, 0);
}

在此处查找相关帖子。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM