欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

實(shí)踐過(guò)程

效果

代碼

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)文章

  • C#難點(diǎn)逐個(gè)擊破(5):類的訪問(wèn)類型

    C#難點(diǎn)逐個(gè)擊破(5):類的訪問(wèn)類型

    類的訪問(wèn)類型有時(shí)也叫訪問(wèn)級(jí)別,使用以下訪問(wèn)修改符:Public、Protected、Private、internal、protected internal。
    2010-02-02
  • c#使用dynamic類型優(yōu)化反射的方法

    c#使用dynamic類型優(yōu)化反射的方法

    dynamic是FrameWork4.0的新特性,下面這篇文章主要給大家介紹了關(guān)于c#使用dynamic類型優(yōu)化反射的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2018-12-12
  • C#實(shí)現(xiàn)創(chuàng)建,刪除,查找,配置虛擬目錄實(shí)例詳解

    C#實(shí)現(xiàn)創(chuàng)建,刪除,查找,配置虛擬目錄實(shí)例詳解

    這篇文章主要介紹了C#創(chuàng)建,刪除,查找,配置虛擬目錄的方法,以實(shí)例形式較為詳細(xì)的分析了C#針對(duì)虛擬目錄的創(chuàng)建、刪除、查找等相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-08-08
  • 詳解c# 并行計(jì)算

    詳解c# 并行計(jì)算

    本文主要介紹了并行計(jì)算的簡(jiǎn)單使用,并行循環(huán)的中斷和跳出、并行循環(huán)中為數(shù)組/集合添加項(xiàng)、返回集合運(yùn)算結(jié)果/含有局部變量的并行循環(huán)、、PLinq(Linq的并行計(jì)算)等相關(guān)內(nèi)容。
    2020-12-12
  • C#實(shí)現(xiàn)簡(jiǎn)單成績(jī)管理系統(tǒng)的完整步驟

    C#實(shí)現(xiàn)簡(jiǎn)單成績(jī)管理系統(tǒng)的完整步驟

    這篇文章主要給大家介紹了關(guān)于C#實(shí)現(xiàn)簡(jiǎn)單成績(jī)管理系統(tǒng)的完整步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者使用C#具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • C#浮點(diǎn)數(shù)的表示和基本運(yùn)算

    C#浮點(diǎn)數(shù)的表示和基本運(yùn)算

    這篇文章主要介紹了C#浮點(diǎn)數(shù)的表示和基本運(yùn)算,需要的朋友可以參考下
    2016-12-12
  • C#后臺(tái)創(chuàng)建控件并獲取值的方法

    C#后臺(tái)創(chuàng)建控件并獲取值的方法

    這篇文章主要介紹了C#后臺(tái)創(chuàng)建控件并獲取值的方法,實(shí)例講述了前臺(tái)與后臺(tái)的具體實(shí)現(xiàn)方法,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-01-01
  • Unity創(chuàng)建平鋪網(wǎng)格地圖的方法

    Unity創(chuàng)建平鋪網(wǎng)格地圖的方法

    這篇文章主要為大家詳細(xì)介紹了Unity創(chuàng)建平鋪網(wǎng)格地圖的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • C#查找素?cái)?shù)實(shí)現(xiàn)方法

    C#查找素?cái)?shù)實(shí)現(xiàn)方法

    這篇文章主要介紹了C#查找素?cái)?shù)實(shí)現(xiàn)方法,程序中有很多使用的功能模塊,非常適合C#初學(xué)者學(xué)習(xí)借鑒,需要的朋友可以參考下
    2014-08-08
  • Unity使用多態(tài)制作計(jì)算器功能

    Unity使用多態(tài)制作計(jì)算器功能

    這篇文章主要為大家詳細(xì)介紹了Unity使用多態(tài)制作計(jì)算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08

最新評(píng)論