RGB565调色板Ver1.0.0

/**** RGB565 调色板****/
/**** 使用步骤
1 创建C#应用程序
2 再画图工具 截取 ‘编辑原色’ 保存为 RGB.png
3 复制本文代码。
4 在“pictureBox1”载入 RGB.png图片,然后编译即可
****/
/*****************************************************************************************
                            RGB565 调色板
功能:通过输入RGB值,或者拖动滚条,分别显示RGB和合成的颜色
编者:张永辉 2013年4月16日 第一个版本
*****************************************************************************************/
//Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace cs_test3
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new RGB565调试板());
        }
    }
}

/****************************************************************************************/
//Form1.cs
sing System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace cs_test3
{
    public partial class RGB565调试板 : Form
    {
        public RGB565调试板()
        {
            InitializeComponent();

            R = 0;
            G = 0;
            B = 0;
            DisColorNew();

            textBox3_r.Text = "0";
            textBox_g.Text = "0";
            textBox_b.Text = "0";
        }

        //三颜色定义
        int R;
        int G;
        int B;
        //----------------刷新颜色函数--------------------------------
        private void DisColorNew()
        {
            Color c = Color.FromArgb(R, G, B);
            richTextBox1.BackColor = c;         //合成颜色

            int rgb = ((R >> 3) << 11) + ((G >> 2) << 5) + (B >> 3);
            textBox_RGB.Text = rgb.ToString();

            c = Color.FromArgb(R, 0, 0);        //R
            textBox_RR.BackColor = c;
            c = Color.FromArgb(0, G, 0);        //G
            textBox_GG.BackColor = c;
            c = Color.FromArgb(0, 0, B);        //B
            textBox_BB.BackColor = c;
        }

        //通过拖动条改变颜色
        //R
        private void trackBar_r_Scroll(object sender, EventArgs e)
        {
            int c = trackBar_r.Value;       //获取设定值
            if (c > 31)                     //5位红色  0--31
            {
                c = 31;
            }
            textBox3_r.Text = c.ToString(); //显示值
            c = c << 3;
            R = c;
            DisColorNew();                  //刷新颜色
        }
        //G
        private void trackBar_g_Scroll(object sender, EventArgs e)
        {
            int c = trackBar_g.Value;
            if (c > 63)
            {
                c = 63;
            }
            textBox_g.Text = c.ToString();
            c = c << 2;
            G = c;
            DisColorNew();
        }
        //B
        private void trackBar_b_Scroll(object sender, EventArgs e)
        {
            int c = trackBar_b.Value;
            if (c > 31)
            {
                c = 31;
            }
            textBox_b.Text = c.ToString();
            c = c << 3;
            B = c;
            DisColorNew();
        }

        //----------------通过输入数字调整原色--------------------------
        //R
        private void textBox3_r_TextChanged(object sender, EventArgs e)
        {
            string str = textBox3_r.Text;
            int c;
            int.TryParse(str, out c);
            if (c > 31)                     //5位红色  0--31
            {
                c = 31;
            }
            trackBar_r.Value = c;           //刷新 拖动条
            c = c << 3;
            R = c;
            DisColorNew();                  //刷新颜色
        }

        private void textBox_g_TextChanged(object sender, EventArgs e)
        {
            string str = textBox_g.Text;
            int c;
            int.TryParse(str, out c);
            if (c > 63)
            {
                c = 63;
            }
            trackBar_g.Value = c;
            c = c << 2;
            G = c;
            DisColorNew();
        }

        private void textBox_b_TextChanged(object sender, EventArgs e)
        {
            string str = textBox_b.Text;
            int c;
            int.TryParse(str, out c);
            if (c > 31)
            {
                c = 31;
            }
            trackBar_b.Value = c;
            c = c << 3;
            B = c;
            DisColorNew();
        }

        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
           
            string S = pictureBox1.BackColor.B.ToString();
            S = pictureBox1.SizeMode.ToString();
        }
    }
}
/****************************************************************************************/
//Form1.Designer.cs
namespace cs_test3
{
    partial class RGB565调试板
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.trackBar_r = new System.Windows.Forms.TrackBar();
            this.richTextBox1 = new System.Windows.Forms.RichTextBox();
            this.trackBar_g = new System.Windows.Forms.TrackBar();
            this.trackBar_b = new System.Windows.Forms.TrackBar();
            this.textBox_b = new System.Windows.Forms.TextBox();
            this.textBox_g = new System.Windows.Forms.TextBox();
            this.textBox3_r = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.textBox_RR = new System.Windows.Forms.TextBox();
            this.textBox_GG = new System.Windows.Forms.TextBox();
            this.textBox_BB = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            this.textBox_RGB = new System.Windows.Forms.TextBox();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_r)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_g)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_b)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.SuspendLayout();
            //
            // trackBar_r
            //
            this.trackBar_r.AccessibleRole = System.Windows.Forms.AccessibleRole.None;
            this.trackBar_r.Location = new System.Drawing.Point(31, 57);
            this.trackBar_r.Maximum = 31;
            this.trackBar_r.Name = "trackBar_r";
            this.trackBar_r.Size = new System.Drawing.Size(222, 45);
            this.trackBar_r.TabIndex = 2;
            this.trackBar_r.Scroll += new System.EventHandler(this.trackBar_r_Scroll);
            //
            // richTextBox1
            //
            this.richTextBox1.Location = new System.Drawing.Point(320, 57);
            this.richTextBox1.Name = "richTextBox1";
            this.richTextBox1.Size = new System.Drawing.Size(107, 141);
            this.richTextBox1.TabIndex = 1;
            this.richTextBox1.Text = "";
            //
            // trackBar_g
            //
            this.trackBar_g.Location = new System.Drawing.Point(31, 134);
            this.trackBar_g.Maximum = 63;
            this.trackBar_g.Name = "trackBar_g";
            this.trackBar_g.Size = new System.Drawing.Size(222, 45);
            this.trackBar_g.TabIndex = 3;
            this.trackBar_g.Scroll += new System.EventHandler(this.trackBar_g_Scroll);
            //
            // trackBar_b
            //
            this.trackBar_b.Location = new System.Drawing.Point(31, 219);
            this.trackBar_b.Maximum = 31;
            this.trackBar_b.Name = "trackBar_b";
            this.trackBar_b.Size = new System.Drawing.Size(222, 45);
            this.trackBar_b.TabIndex = 4;
            this.trackBar_b.Scroll += new System.EventHandler(this.trackBar_b_Scroll);
            //
            // textBox_b
            //
            this.textBox_b.AllowDrop = true;
            this.textBox_b.Location = new System.Drawing.Point(40, 192);
            this.textBox_b.Name = "textBox_b";
            this.textBox_b.Size = new System.Drawing.Size(63, 21);
            this.textBox_b.TabIndex = 6;
            this.textBox_b.TextChanged += new System.EventHandler(this.textBox_b_TextChanged);
            //
            // textBox_g
            //
            this.textBox_g.AccessibleRole = System.Windows.Forms.AccessibleRole.None;
            this.textBox_g.Location = new System.Drawing.Point(40, 105);
            this.textBox_g.Name = "textBox_g";
            this.textBox_g.Size = new System.Drawing.Size(63, 21);
            this.textBox_g.TabIndex = 7;
            this.textBox_g.TextChanged += new System.EventHandler(this.textBox_g_TextChanged);
            //
            // textBox3_r
            //
            this.textBox3_r.AccessibleRole = System.Windows.Forms.AccessibleRole.None;
            this.textBox3_r.Location = new System.Drawing.Point(40, 30);
            this.textBox3_r.Name = "textBox3_r";
            this.textBox3_r.Size = new System.Drawing.Size(63, 21);
            this.textBox3_r.TabIndex = 8;
            this.textBox3_r.TextChanged += new System.EventHandler(this.textBox3_r_TextChanged);
            //
            // label1
            //
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(122, 30);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(11, 12);
            this.label1.TabIndex = 9;
            this.label1.Text = "R";
            //
            // label2
            //
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(124, 105);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(11, 12);
            this.label2.TabIndex = 10;
            this.label2.Text = "G";
            //
            // label3
            //
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(126, 192);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(11, 12);
            this.label3.TabIndex = 11;
            this.label3.Text = "B";
            //
            // textBox_RR
            //
            this.textBox_RR.Location = new System.Drawing.Point(202, 30);
            this.textBox_RR.Name = "textBox_RR";
            this.textBox_RR.Size = new System.Drawing.Size(51, 21);
            this.textBox_RR.TabIndex = 12;
            //
            // textBox_GG
            //
            this.textBox_GG.Location = new System.Drawing.Point(202, 105);
            this.textBox_GG.Name = "textBox_GG";
            this.textBox_GG.Size = new System.Drawing.Size(51, 21);
            this.textBox_GG.TabIndex = 13;
            //
            // textBox_BB
            //
            this.textBox_BB.Location = new System.Drawing.Point(202, 192);
            this.textBox_BB.Name = "textBox_BB";
            this.textBox_BB.Size = new System.Drawing.Size(51, 21);
            this.textBox_BB.TabIndex = 14;
            //
            // label4
            //
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(338, 210);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(77, 12);
            this.label4.TabIndex = 15;
            this.label4.Text = "zhangyonghui";
            //
            // label5
            //
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(308, 231);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(107, 12);
            this.label5.TabIndex = 16;
            this.label5.Text = "ver1.0.0 20130416";
            //
            // pictureBox1
            //
            this.pictureBox1.Image = global::cs_test3.Properties.Resources.RGB;
            this.pictureBox1.Location = new System.Drawing.Point(457, 27);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(210, 186);
            this.pictureBox1.TabIndex = 17;
            this.pictureBox1.TabStop = false;
            this.pictureBox1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseClick);
            //
            // textBox_RGB
            //
            this.textBox_RGB.Location = new System.Drawing.Point(320, 27);
            this.textBox_RGB.Name = "textBox_RGB";
            this.textBox_RGB.Size = new System.Drawing.Size(100, 21);
            this.textBox_RGB.TabIndex = 18;
            //
            // RGB565调试板
            //
            this.AccessibleRole = System.Windows.Forms.AccessibleRole.None;
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(706, 280);
            this.Controls.Add(this.textBox_RGB);
            this.Controls.Add(this.pictureBox1);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.textBox_BB);
            this.Controls.Add(this.textBox_GG);
            this.Controls.Add(this.textBox_RR);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.textBox3_r);
            this.Controls.Add(this.textBox_g);
            this.Controls.Add(this.textBox_b);
            this.Controls.Add(this.trackBar_b);
            this.Controls.Add(this.trackBar_g);
            this.Controls.Add(this.richTextBox1);
            this.Controls.Add(this.trackBar_r);
            this.Name = "RGB565调试板";
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_r)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_g)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_b)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.TrackBar trackBar_r;
        private System.Windows.Forms.RichTextBox richTextBox1;
        private System.Windows.Forms.TrackBar trackBar_g;
        private System.Windows.Forms.TrackBar trackBar_b;
        private System.Windows.Forms.TextBox textBox_b;
        private System.Windows.Forms.TextBox textBox_g;
        private System.Windows.Forms.TextBox textBox3_r;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.TextBox textBox_RR;
        private System.Windows.Forms.TextBox textBox_GG;
        private System.Windows.Forms.TextBox textBox_BB;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.PictureBox pictureBox1;
        private System.Windows.Forms.TextBox textBox_RGB;
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值