最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于C#實(shí)現(xiàn)屏幕取色器的示例詳解

 更新時(shí)間:2022年12月09日 11:21:55   作者:芝麻粒兒  
這篇文章主要為大家詳細(xì)介紹了如何利用C#實(shí)現(xiàn)屏幕取色器,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以了解一下

實(shí)踐過程

效果

代碼

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    [DllImport("gdi32.dll")]
    static public extern uint GetPixel(IntPtr hDC, int XPos, int YPos);

    [DllImport("gdi32.dll")]
    static public extern IntPtr CreateDC(string driverName, string deviceName, string output, IntPtr lpinitData);

    [DllImport("gdi32.dll")]
    static public extern bool DeleteDC(IntPtr DC);

    static public byte GetRValue(uint color)
    {
        return (byte) color;
    }

    static public byte GetGValue(uint color)
    {
        return ((byte) (((short) (color)) >> 8));
    }

    static public byte GetBValue(uint color)
    {
        return ((byte) ((color) >> 16));
    }

    static public byte GetAValue(uint color)
    {
        return ((byte) ((color) >> 24));
    }

    public Color GetColor(Point screenPoint)
    {
        IntPtr displayDC = CreateDC("DISPLAY", null, null, IntPtr.Zero);
        uint colorref = GetPixel(displayDC, screenPoint.X, screenPoint.Y);
        DeleteDC(displayDC);
        byte Red = GetRValue(colorref);
        byte Green = GetGValue(colorref);
        byte Blue = GetBValue(colorref);
        return Color.FromArgb(Red, Green, Blue);
    }

    private void Form1_Load(object sender, EventArgs e)
    {
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        Point pt = new Point(Control.MousePosition.X, Control.MousePosition.Y);
        Color cl = GetColor(pt);
        panel1.BackColor = cl;
    }
}
partial class Form1
{
    /// <summary>
    /// 必需的設(shè)計(jì)器變量。
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// 清理所有正在使用的資源。
    /// </summary>
    /// <param name="disposing">如果應(yīng)釋放托管資源,為 true;否則為 false。</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows 窗體設(shè)計(jì)器生成的代碼

    /// <summary>
    /// 設(shè)計(jì)器支持所需的方法 - 不要
    /// 使用代碼編輯器修改此方法的內(nèi)容。
    /// </summary>
    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        this.timer1 = new System.Windows.Forms.Timer(this.components);
        this.panel1 = new System.Windows.Forms.Panel();
        this.SuspendLayout();
        // 
        // timer1
        // 
        this.timer1.Enabled = true;
        this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
        // 
        // panel1
        // 
        this.panel1.Location = new System.Drawing.Point(12, 12);
        this.panel1.Name = "panel1";
        this.panel1.Size = new System.Drawing.Size(200, 100);
        this.panel1.TabIndex = 0;
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(535, 298);
        this.Controls.Add(this.panel1);
        this.Name = "Form1";
        this.Text = "Form1";
        this.Load += new System.EventHandler(this.Form1_Load);
        this.ResumeLayout(false);

    }

    #endregion

    private System.Windows.Forms.Timer timer1;
    private System.Windows.Forms.Panel panel1;
}

到此這篇關(guān)于基于C#實(shí)現(xiàn)屏幕取色器的示例詳解的文章就介紹到這了,更多相關(guān)C#屏幕取色器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

中阳县| 广饶县| 工布江达县| 方正县| 荥阳市| 阿瓦提县| 华容县| 虹口区| 阿巴嘎旗| 宁晋县| 乌拉特前旗| 沂源县| 岳阳县| 驻马店市| 隆林| 宁城县| 双城市| 龙里县| 万源市| 精河县| 英吉沙县| 沈丘县| 南安市| 泗水县| 古交市| 墨竹工卡县| 九龙城区| 西乌| 仁化县| 无为县| 连江县| 肃南| 师宗县| 福清市| 曲水县| 界首市| 余庆县| 台北县| 沂源县| 原平市| 兖州市|