System.Drawing.Color.FromArgb(int, int, int, int)

Here are the examples of the csharp api System.Drawing.Color.FromArgb(int, int, int, int) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1041 Examples 7

19 View Source File : FSwitchBox.cs
License : MIT License
Project Creator : 0xLaileb

private void Draw_Checked(Graphics graphics)
        {
            //RoundedRectangle
            Rectangle rectangle_new = new Rectangle();

            if (Checked)
            {
                int num_X = (int)((rectangle_region.Width / 10) * 6.2F);
                int num_Y = rectangle_region.Height / 6;
                rectangle_new.X = rectangle_region.X + num_X;
                rectangle_new.Y = rectangle_region.Y + num_Y;
                rectangle_new.Height = rectangle_region.Height - num_Y * 2;
                rectangle_new.Width = rectangle_new.Height;

                if (LinearGradient_Value) graphics.FillEllipse(new LinearGradientBrush(rectangle_region,
                    RGB ? DrawEngine.HSV_To_RGB(h, 1f, 1f) : ColorBackground_Value_1,
                    RGB ? DrawEngine.HSV_To_RGB(h + 20, 1f, 1f) : ColorBackground_Value_2,
                    360), rectangle_new);
                else graphics.FillEllipse(new SolidBrush(
                    RGB ? DrawEngine.HSV_To_RGB(h, 1f, 1f) : ColorValue), rectangle_new);
            }
            else
            {
                int num_X = rectangle_region.Width / 10;
                int num_Y = rectangle_region.Height / 6;
                rectangle_new.X = rectangle_region.X + num_X;
                rectangle_new.Y = rectangle_region.Y + num_Y;
                rectangle_new.Height = rectangle_region.Height - num_Y * 2;
                rectangle_new.Width = rectangle_new.Height;
                float size_brightness = 0.5F;

                if (LinearGradient_Value) graphics.FillEllipse(new LinearGradientBrush(rectangle_region,
                    Color.FromArgb(
                    (int)((RGB ? DrawEngine.HSV_To_RGB(h, 1f, 1f) : ColorBackground_Value_1).R * size_brightness),
                    (int)((RGB ? DrawEngine.HSV_To_RGB(h, 1f, 1f) : ColorBackground_Value_1).G * size_brightness),
                    (int)((RGB ? DrawEngine.HSV_To_RGB(h, 1f, 1f) : ColorBackground_Value_1).B * size_brightness)),
                    Color.FromArgb(
                    (int)((RGB ? DrawEngine.HSV_To_RGB(h + 20, 1f, 1f) : ColorBackground_Value_2).R * size_brightness),
                    (int)((RGB ? DrawEngine.HSV_To_RGB(h + 20, 1f, 1f) : ColorBackground_Value_2).G * size_brightness),
                    (int)((RGB ? DrawEngine.HSV_To_RGB(h + 20, 1f, 1f) : ColorBackground_Value_2).B * size_brightness)),
                    360), rectangle_new);
                else graphics.FillEllipse(new SolidBrush(Color.FromArgb(100,
                    (int)((RGB ? DrawEngine.HSV_To_RGB(h, 1f, 1f) : ColorValue).R * size_brightness),
                    (int)((RGB ? DrawEngine.HSV_To_RGB(h, 1f, 1f) : ColorValue).G * size_brightness),
                    (int)((RGB ? DrawEngine.HSV_To_RGB(h, 1f, 1f) : ColorValue).B * size_brightness))), rectangle_new);
            }
        }

19 View Source File : DrawEngine.cs
License : MIT License
Project Creator : 0xLaileb

public static Color HSV_To_RGB(float hue, float saturation, float value)
        {
            if (saturation < float.Epsilon)
            {
                int c = (int)(value * 255);
                return Color.FromArgb(c, c, c);
            }
            if (timer_global_rgb.Enabled) hue = h_temp;

            float r, g, b, f, p, q, t;
            int i;

            hue /= 60;
            i = (int)Math.Floor(hue);

            f = hue - i;
            p = value * (1 - saturation);
            q = value * (1 - saturation * f);
            t = value * (1 - saturation * (1 - f));

            switch (i)
            {
                case 0: r = value; g = t; b = p; break;
                case 1: r = q; g = value; b = p; break;
                case 2: r = p; g = value; b = t; break;
                case 3: r = p; g = q; b = value; break;
                case 4: r = t; g = p; b = value; break;
                default: r = value; g = p; b = q; break;
            }
            return Color.FromArgb(255, (int)(r * 255), (int)(g * 255), (int)(b * 255));
        }

19 View Source File : HelpEngine.cs
License : MIT License
Project Creator : 0xLaileb

public Color ColorArgb(int alpha = 255) => Color.FromArgb(alpha, Int(0, 255), Int(0, 255), Int(0, 255));

19 View Source File : GH_Cloud.cs
License : GNU Lesser General Public License v3.0
Project Creator : 9and3

public void DrawViewportWires(GH_PreviewWireArgs args) {
            if (this.m_value != null) {
                if (StaticParameters.DisplayPositions) {
                    args.Pipeline.DrawLines(this.CreatePosLines(CentralSettings.PreviewPlaneRadius), args.Color, checked(args.Thickness * 2));
                    List<Line> lines = this.CreateAxes(CentralSettings.PreviewPlaneRadius);
                    Color previewColourSelected = Grreplacedhopper.Instances.ActiveCanvas.Doreplacedent.PreviewColourSelected;
                    previewColourSelected = Color.FromArgb(255, (int)previewColourSelected.R, (int)previewColourSelected.G, (int)previewColourSelected.B);
                    if (previewColourSelected != args.Color) {
                        args.Pipeline.DrawLine(lines[0], Rhino.ApplicationSettings.AppearanceSettings.GridXAxisLineColor, checked(args.Thickness * 2));
                        args.Pipeline.DrawLine(lines[1], Rhino.ApplicationSettings.AppearanceSettings.GridYAxisLineColor, checked(args.Thickness * 2));
                        args.Pipeline.DrawLine(lines[2], Rhino.ApplicationSettings.AppearanceSettings.GridZAxisLineColor, checked(args.Thickness * 2));
                    } else {
                        args.Pipeline.DrawLine(lines[0], args.Color, checked(args.Thickness * 2));
                        args.Pipeline.DrawLine(lines[1], args.Color, checked(args.Thickness * 2));
                        args.Pipeline.DrawLine(lines[2], args.Color, checked(args.Thickness * 2));
                    }
                }
                if (StaticParameters.DisplayDynamic) {
                    if (!args.Pipeline.IsDynamicDisplay) {
                        args.Pipeline.DrawPointCloud(this.m_value, StaticParameters.DisplayRadius, args.Color);
                        return;
                    }
                    this.ResolveDisplay();
                    args.Pipeline.DrawPointCloud(this.DisplayCloud, checked(StaticParameters.DisplayRadius + 1), args.Color);
                    return;
                }
                args.Pipeline.DrawPointCloud(this.m_value, StaticParameters.DisplayRadius, args.Color);
            }
        }

19 View Source File : WaitFm.Designer.cs
License : GNU General Public License v3.0
Project Creator : a4004

private void InitializeComponent()
        {
            this.taskreplacedle = new System.Windows.Forms.Label();
            this.taskCaption = new System.Windows.Forms.Label();
            this.lnkVerbose = new System.Windows.Forms.LinkLabel();
            this.detailView = new System.Windows.Forms.Panel();
            this.debugOutput = new System.Windows.Forms.ListBox();
            this.header = new System.Windows.Forms.Panel();
            this.container = new System.Windows.Forms.Panel();
            this.extendedSpinner = new N2D22.Controls.ExtendedSpinner();
            this.detailView.SuspendLayout();
            this.header.SuspendLayout();
            this.container.SuspendLayout();
            this.SuspendLayout();
            // 
            // taskreplacedle
            // 
            this.taskreplacedle.AutoSize = true;
            this.taskreplacedle.Dock = System.Windows.Forms.DockStyle.Left;
            this.taskreplacedle.Font = new System.Drawing.Font("Segoe UI Semilight", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.taskreplacedle.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(97)))), ((int)(((byte)(255)))));
            this.taskreplacedle.Location = new System.Drawing.Point(0, 0);
            this.taskreplacedle.Name = "taskreplacedle";
            this.taskreplacedle.Size = new System.Drawing.Size(101, 32);
            this.taskreplacedle.TabIndex = 0;
            this.taskreplacedle.Text = "Working";
            this.taskreplacedle.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // taskCaption
            // 
            this.taskCaption.Dock = System.Windows.Forms.DockStyle.Top;
            this.taskCaption.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.taskCaption.Location = new System.Drawing.Point(15, 52);
            this.taskCaption.Name = "taskCaption";
            this.taskCaption.Padding = new System.Windows.Forms.Padding(3, 0, 8, 0);
            this.taskCaption.Size = new System.Drawing.Size(570, 43);
            this.taskCaption.TabIndex = 1;
            this.taskCaption.Text = "This won\'t take long";
            // 
            // lnkVerbose
            // 
            this.lnkVerbose.ActiveLinkColor = System.Drawing.Color.Blue;
            this.lnkVerbose.AutoEllipsis = true;
            this.lnkVerbose.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.lnkVerbose.LinkColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(97)))), ((int)(((byte)(255)))));
            this.lnkVerbose.Location = new System.Drawing.Point(15, 343);
            this.lnkVerbose.Name = "lnkVerbose";
            this.lnkVerbose.Size = new System.Drawing.Size(570, 32);
            this.lnkVerbose.TabIndex = 2;
            this.lnkVerbose.TabStop = true;
            this.lnkVerbose.Text = "Show Details";
            this.lnkVerbose.TextAlign = System.Drawing.ContentAlignment.BottomRight;
            this.lnkVerbose.VisitedLinkColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(97)))), ((int)(((byte)(255)))));
            this.lnkVerbose.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkVerbose_LinkClicked);
            // 
            // detailView
            // 
            this.detailView.BackColor = System.Drawing.SystemColors.Window;
            this.detailView.Controls.Add(this.debugOutput);
            this.detailView.Dock = System.Windows.Forms.DockStyle.Fill;
            this.detailView.Location = new System.Drawing.Point(15, 95);
            this.detailView.Name = "detailView";
            this.detailView.Padding = new System.Windows.Forms.Padding(5, 15, 5, 0);
            this.detailView.Size = new System.Drawing.Size(570, 248);
            this.detailView.TabIndex = 3;
            this.detailView.Visible = false;
            // 
            // debugOutput
            // 
            this.debugOutput.Dock = System.Windows.Forms.DockStyle.Fill;
            this.debugOutput.Font = new System.Drawing.Font("Consolas", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.debugOutput.FormattingEnabled = true;
            this.debugOutput.HorizontalScrollbar = true;
            this.debugOutput.ItemHeight = 15;
            this.debugOutput.Location = new System.Drawing.Point(5, 15);
            this.debugOutput.Name = "debugOutput";
            this.debugOutput.Size = new System.Drawing.Size(560, 233);
            this.debugOutput.TabIndex = 0;
            // 
            // header
            // 
            this.header.Controls.Add(this.container);
            this.header.Controls.Add(this.taskreplacedle);
            this.header.Dock = System.Windows.Forms.DockStyle.Top;
            this.header.Location = new System.Drawing.Point(15, 16);
            this.header.Name = "header";
            this.header.Size = new System.Drawing.Size(570, 36);
            this.header.TabIndex = 1;
            // 
            // container
            // 
            this.container.Controls.Add(this.extendedSpinner);
            this.container.Dock = System.Windows.Forms.DockStyle.Left;
            this.container.Location = new System.Drawing.Point(101, 0);
            this.container.Name = "container";
            this.container.Padding = new System.Windows.Forms.Padding(9, 4, 9, 8);
            this.container.Size = new System.Drawing.Size(42, 36);
            this.container.TabIndex = 8;
            // 
            // extendedSpinner
            // 
            this.extendedSpinner.Animated = true;
            this.extendedSpinner.BackObjectColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
            this.extendedSpinner.BackThickness = 2;
            this.extendedSpinner.ColorOne = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(97)))), ((int)(((byte)(255)))));
            this.extendedSpinner.ColorTwo = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(97)))), ((int)(((byte)(255)))));
            this.extendedSpinner.Dock = System.Windows.Forms.DockStyle.Fill;
            this.extendedSpinner.Gradient = false;
            this.extendedSpinner.Location = new System.Drawing.Point(9, 4);
            this.extendedSpinner.Name = "extendedSpinner";
            this.extendedSpinner.ObjectColor = System.Drawing.Color.DodgerBlue;
            this.extendedSpinner.Size = new System.Drawing.Size(24, 24);
            this.extendedSpinner.Speed = 7;
            this.extendedSpinner.TabIndex = 10;
            this.extendedSpinner.Thickness = 2;
            this.extendedSpinner.Trail = true;
            this.extendedSpinner.Value = 50;
            // 
            // WaitFm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.SystemColors.Window;
            this.ClientSize = new System.Drawing.Size(600, 400);
            this.Controls.Add(this.detailView);
            this.Controls.Add(this.lnkVerbose);
            this.Controls.Add(this.taskCaption);
            this.Controls.Add(this.header);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.Name = "WaitFm";
            this.Padding = new System.Windows.Forms.Padding(15, 16, 15, 25);
            this.detailView.ResumeLayout(false);
            this.header.ResumeLayout(false);
            this.header.PerformLayout();
            this.container.ResumeLayout(false);
            this.ResumeLayout(false);

        }

19 View Source File : UI.Designer.cs
License : MIT License
Project Creator : aaaddress1

private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UI));
            this.splitContainer = new System.Windows.Forms.SplitContainer();
            this.fastColoredTextBox = new FastColoredTextBoxNS.FastColoredTextBox();
            this.toolbox = new System.Windows.Forms.ToolStrip();
            this.compile = new System.Windows.Forms.ToolStripButton();
            this.run = new System.Windows.Forms.ToolStripButton();
            this.config = new System.Windows.Forms.ToolStripButton();
            this.browse = new System.Windows.Forms.ToolStripButton();
            this.logPanelBtn = new System.Windows.Forms.ToolStripButton();
            this.Snippet = new System.Windows.Forms.ToolStripDropDownButton();
            this.runPEToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.about = new System.Windows.Forms.ToolStripButton();
            this.percntLB = new System.Windows.Forms.ToolStripLabel();
            this.logBox = new System.Windows.Forms.RichTextBox();
            this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
            this.splitContainer.Panel1.SuspendLayout();
            this.splitContainer.Panel2.SuspendLayout();
            this.splitContainer.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.fastColoredTextBox)).BeginInit();
            this.toolbox.SuspendLayout();
            this.SuspendLayout();
            // 
            // splitContainer
            // 
            this.splitContainer.BackColor = System.Drawing.SystemColors.Control;
            this.splitContainer.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.splitContainer.Dock = System.Windows.Forms.DockStyle.Fill;
            this.splitContainer.Location = new System.Drawing.Point(0, 0);
            this.splitContainer.Name = "splitContainer";
            this.splitContainer.Orientation = System.Windows.Forms.Orientation.Horizontal;
            // 
            // splitContainer.Panel1
            // 
            this.splitContainer.Panel1.Controls.Add(this.fastColoredTextBox);
            this.splitContainer.Panel1.Controls.Add(this.toolbox);
            // 
            // splitContainer.Panel2
            // 
            this.splitContainer.Panel2.Controls.Add(this.logBox);
            this.splitContainer.Size = new System.Drawing.Size(791, 351);
            this.splitContainer.SplitterDistance = 169;
            this.splitContainer.SplitterWidth = 1;
            this.splitContainer.TabIndex = 5;
            // 
            // fastColoredTextBox
            // 
            this.fastColoredTextBox.AutoCompleteBracketsList = new char[] {
        '(',
        ')',
        '{',
        '}',
        '[',
        ']',
        '\"',
        '\"',
        '\'',
        '\''};
            this.fastColoredTextBox.AutoScrollMinSize = new System.Drawing.Size(27, 14);
            this.fastColoredTextBox.BackBrush = null;
            this.fastColoredTextBox.CharHeight = 14;
            this.fastColoredTextBox.CharWidth = 8;
            this.fastColoredTextBox.Cursor = System.Windows.Forms.Cursors.IBeam;
            this.fastColoredTextBox.DisabledColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(180)))), ((int)(((byte)(180)))), ((int)(((byte)(180)))));
            this.fastColoredTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
            this.fastColoredTextBox.IsReplaceMode = false;
            this.fastColoredTextBox.Location = new System.Drawing.Point(0, 0);
            this.fastColoredTextBox.Name = "fastColoredTextBox";
            this.fastColoredTextBox.Paddings = new System.Windows.Forms.Padding(0);
            this.fastColoredTextBox.SelectionColor = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(255)))));
            this.fastColoredTextBox.ServiceColors = ((FastColoredTextBoxNS.ServiceColors)(resources.GetObject("fastColoredTextBox.ServiceColors")));
            this.fastColoredTextBox.Size = new System.Drawing.Size(789, 128);
            this.fastColoredTextBox.TabIndex = 8;
            this.fastColoredTextBox.Zoom = 100;
            // 
            // toolbox
            // 
            this.toolbox.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.toolbox.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
            this.toolbox.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.compile,
            this.run,
            this.config,
            this.browse,
            this.logPanelBtn,
            this.Snippet,
            this.about,
            this.percntLB});
            this.toolbox.Location = new System.Drawing.Point(0, 128);
            this.toolbox.Name = "toolbox";
            this.toolbox.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;
            this.toolbox.Size = new System.Drawing.Size(789, 39);
            this.toolbox.Stretch = true;
            this.toolbox.TabIndex = 7;
            this.toolbox.Text = "toolStrip";
            // 
            // compile
            // 
            this.compile.Image = ((System.Drawing.Image)(resources.GetObject("compile.Image")));
            this.compile.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
            this.compile.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.compile.Name = "compile";
            this.compile.Size = new System.Drawing.Size(92, 36);
            this.compile.Text = "&Compile";
            this.compile.ToolTipText = "Compile";
            this.compile.Click += new System.EventHandler(this.compile_Click);
            // 
            // run
            // 
            this.run.Image = ((System.Drawing.Image)(resources.GetObject("run.Image")));
            this.run.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
            this.run.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.run.Name = "run";
            this.run.Size = new System.Drawing.Size(66, 36);
            this.run.Text = "&Run";
            this.run.ToolTipText = "Run";
            this.run.Click += new System.EventHandler(this.run_Click);
            // 
            // config
            // 
            this.config.Image = ((System.Drawing.Image)(resources.GetObject("config.Image")));
            this.config.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
            this.config.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.config.Name = "config";
            this.config.Size = new System.Drawing.Size(82, 36);
            this.config.Text = "&Config";
            this.config.ToolTipText = "Config";
            this.config.Click += new System.EventHandler(this.config_Click);
            // 
            // browse
            // 
            this.browse.Image = ((System.Drawing.Image)(resources.GetObject("browse.Image")));
            this.browse.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
            this.browse.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.browse.Name = "browse";
            this.browse.Size = new System.Drawing.Size(84, 36);
            this.browse.Text = "&Browse";
            this.browse.ToolTipText = "Browse";
            this.browse.Click += new System.EventHandler(this.browse_Click);
            // 
            // logPanelBtn
            // 
            this.logPanelBtn.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
            this.logPanelBtn.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
            this.logPanelBtn.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.logPanelBtn.Name = "logPanelBtn";
            this.logPanelBtn.Size = new System.Drawing.Size(23, 36);
            this.logPanelBtn.Text = "+";
            this.logPanelBtn.ToolTipText = "Log Panel";
            this.logPanelBtn.Click += new System.EventHandler(this.logPanelBtn_Click);
            // 
            // Snippet
            // 
            this.Snippet.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.runPEToolStripMenuItem});
            this.Snippet.Image = ((System.Drawing.Image)(resources.GetObject("Snippet.Image")));
            this.Snippet.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
            this.Snippet.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.Snippet.Name = "Snippet";
            this.Snippet.Size = new System.Drawing.Size(89, 36);
            this.Snippet.Text = "&Snippet";
            // 
            // runPEToolStripMenuItem
            // 
            this.runPEToolStripMenuItem.Name = "runPEToolStripMenuItem";
            this.runPEToolStripMenuItem.Size = new System.Drawing.Size(112, 22);
            this.runPEToolStripMenuItem.Text = "RunPE";
            this.runPEToolStripMenuItem.Click += new System.EventHandler(this.runPEToolStripMenuItem_Click);
            // 
            // about
            // 
            this.about.Image = ((System.Drawing.Image)(resources.GetObject("about.Image")));
            this.about.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
            this.about.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.about.Name = "about";
            this.about.Size = new System.Drawing.Size(79, 36);
            this.about.Text = "&About";
            this.about.ToolTipText = "About";
            this.about.Click += new System.EventHandler(this.about_Click);
            // 
            // percntLB
            // 
            this.percntLB.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
            this.percntLB.Name = "percntLB";
            this.percntLB.Size = new System.Drawing.Size(40, 36);
            this.percntLB.Text = "100%";
            // 
            // logBox
            // 
            this.logBox.AcceptsTab = true;
            this.logBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.logBox.Dock = System.Windows.Forms.DockStyle.Fill;
            this.logBox.Font = new System.Drawing.Font("Courier New", 9.75F);
            this.logBox.Location = new System.Drawing.Point(0, 0);
            this.logBox.Name = "logBox";
            this.logBox.Size = new System.Drawing.Size(789, 179);
            this.logBox.TabIndex = 9;
            this.logBox.Text = "";
            // 
            // openFileDialog
            // 
            this.openFileDialog.FileName = "openFileDialog";
            this.openFileDialog.Filter = "Executable File|*.exe";
            this.openFileDialog.replacedle = "Select Your Executable File To Inject";
            // 
            // UI
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(791, 351);
            this.Controls.Add(this.splitContainer);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "UI";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Shown += new System.EventHandler(this.refreshUi);
            this.splitContainer.Panel1.ResumeLayout(false);
            this.splitContainer.Panel1.PerformLayout();
            this.splitContainer.Panel2.ResumeLayout(false);
            this.splitContainer.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.fastColoredTextBox)).EndInit();
            this.toolbox.ResumeLayout(false);
            this.toolbox.PerformLayout();
            this.ResumeLayout(false);

        }

19 View Source File : SqlStyler.cs
License : GNU General Public License v3.0
Project Creator : adam8797

public override void ApplyStyle(ScintillaNET.Scintilla scintilla)
        {
            // Set the Styles
            scintilla.Styles[Style.LineNumber].ForeColor = Color.FromArgb(255, 128, 128, 128); //Dark Gray
            scintilla.Styles[Style.LineNumber].BackColor = Color.FromArgb(255, 228, 228, 228); //Light Gray
            scintilla.Styles[Style.Sql.Comment].ForeColor = Color.Green;
            scintilla.Styles[Style.Sql.CommentLine].ForeColor = Color.Green;
            scintilla.Styles[Style.Sql.CommentLineDoc].ForeColor = Color.Green;
            scintilla.Styles[Style.Sql.Number].ForeColor = Color.Maroon;
            scintilla.Styles[Style.Sql.Word].ForeColor = Color.Blue;
            scintilla.Styles[Style.Sql.Word2].ForeColor = Color.Fuchsia;
            scintilla.Styles[Style.Sql.User1].ForeColor = Color.Gray;
            scintilla.Styles[Style.Sql.User2].ForeColor = Color.FromArgb(255, 00, 128, 192); //Medium Blue-Green
            scintilla.Styles[Style.Sql.String].ForeColor = Color.Red;
            scintilla.Styles[Style.Sql.Character].ForeColor = Color.Red;
            scintilla.Styles[Style.Sql.Operator].ForeColor = Color.Black;
        }

19 View Source File : ColorPicker.cs
License : GNU General Public License v3.0
Project Creator : aglab2

private void pictureBox1_Click(object sender, EventArgs e)
        { 
            double expectedHue = (double)picX / pictureBox.Width;
            double expectedVal = (double)picY / pictureBox.Height;

            pickedColor = ColorRGB.HSL2RGB(expectedHue, 1, expectedVal);

            for (int i = 0; i < img.Width; i++)
            {
                for (int j = 0; j < img.Height; j++)
                {
                    Color c = img.GetPixel(i, j);
                    ColorRGB.RGB2HSL(new ColorRGB(c), out double h, out double s, out double v);
                    h += expectedHue - midHue;
                    if (h < 0) h += 1;
                    if (h > 1) h -= 1;

                    Color o = ColorRGB.HSL2RGB(h, s, v);
                    Color oa = Color.FromArgb(c.A, o.R, o.G, o.B);

                    newImg.SetPixel(i, j, oa);
                }
            }

            Graphics graphics = starPicture.CreateGraphics();
            graphics.Clear(Color.Black);
            graphics.DrawImage(newImg, 0, 0, 220, 220);
        }

19 View Source File : ColorPicker.cs
License : GNU General Public License v3.0
Project Creator : aglab2

private void pictureBox_MouseMove(object sender, MouseEventArgs e)
        {
            picX = e.X; picY = e.Y;
            if (e.Button != MouseButtons.Left) return;

            Bitmap img = ld.goldStar;
            
            double expectedHue = (double) e.X / pictureBox.Width;
            double expectedVal = (double) e.Y / pictureBox.Height;

            pickedColor = ColorRGB.HSL2RGB(expectedHue, 1, expectedVal);

            for (int i = 0; i < img.Width; i++)
            {
                for (int j = 0; j < img.Height; j++)
                {
                    Color c = img.GetPixel(i, j);
                    ColorRGB.RGB2HSL(new ColorRGB(c), out double h, out double s, out double v);
                    h += expectedHue - midHue;
                    if (h < 0) h += 1;
                    if (h > 1) h -= 1;

                    Color o = ColorRGB.HSL2RGB(h, s, v);
                    Color oa = Color.FromArgb(c.A, o.R, o.G, o.B);

                    newImg.SetPixel(i, j, oa);
                }
            }

            Graphics graphics = starPicture.CreateGraphics();
            graphics.Clear(Color.Black);
            graphics.DrawImage(newImg, 0, 0, 220, 220);
        }

19 View Source File : ImageProcessing.cs
License : GNU General Public License v3.0
Project Creator : aglab2

public static Bitmap Invert(Bitmap goldStar)
        {
            Bitmap invStar = new Bitmap(goldStar);
            for (int i = 0; i < goldStar.Width; i++)
            {
                for (int j = 0; j < goldStar.Height; j++)
                {
                    Color c = goldStar.GetPixel(i, j);
                    Color n = Color.FromArgb(c.A, 255 - c.R, 255 - c.G, 255 - c.B);
                    invStar.SetPixel(i, j, n);
                }
            }
            return invStar;
        }

19 View Source File : ImageProcessing.cs
License : GNU General Public License v3.0
Project Creator : aglab2

public static Bitmap GetEmptied(Bitmap goldStar, int size)
        {
            bool IsTupleValid(Tuple<int, int> t)
            {
                if (t.Item1 < 0 || t.Item1 >= goldStar.Width)
                    return false;

                if (t.Item2 < 0 || t.Item2 >= goldStar.Height)
                    return false;

                return true;
            }

            List<Tuple<int, int>> GetIndices(int x, int y)
            {
                List<Tuple<int, int>> indices = new List<Tuple<int, int>>();
                for (int i = -size; i <= size; i++)
                {
                    for (int j = -size; j <= size; j++)
                    {
                        if (i == 0 && j == 0)
                            continue;

                        var pos = new Tuple<int, int>(x - i, y - j);
                        if (!IsTupleValid(pos))
                            continue;

                        indices.Add(pos);
                    }
                }
                return indices;
            }

            Bitmap darkStar = new Bitmap(goldStar);
            for (int i = 0; i < goldStar.Width; i++)
            {
                for (int j = 0; j < goldStar.Height; j++)
                {
                    var indices = GetIndices(i, j);
                    var alphas = indices.Select(t => goldStar.GetPixel(t.Item1, t.Item2).A);
                    var visibleCount = alphas.Where(a => a == 0xff).Count();
                    var invisibleCount = alphas.Count() - visibleCount;
                    var totalCount = indices.Count();

                    Color c = goldStar.GetPixel(i, j);
                    if (invisibleCount == totalCount)
                    {
                        darkStar.SetPixel(i, j, c);
                    }
                    else
                    {
                        darkStar.SetPixel(i, j, Color.FromArgb((int) ((float) invisibleCount / (float) alphas.Count() * 255), c.R, c.G, c.B));
                    }
                }
            }
            return darkStar;
        }

19 View Source File : LayoutDescriptionEx.cs
License : GNU General Public License v3.0
Project Creator : aglab2

public void GenerateOutline()
        {
            this.redOutline = new Bitmap(goldStar.Width, goldStar.Height);
            this.greenOutline = new Bitmap(goldStar.Width, goldStar.Height);

            int[,] outlineAlpha = ImageProcessing.GetAlpha(goldStar);
            for (int i = 0; i < 10; i++)
            {
                outlineAlpha = ImageProcessing.OutlineAlpha(outlineAlpha, goldStar);
            }
            for (int i = 0; i < goldStar.Width; i++)
            {
                for (int j = 0; j < goldStar.Height; j++)
                {
                    redOutline.SetPixel(i, j, Color.FromArgb(outlineAlpha[i, j], 255, 0, 0));
                    greenOutline.SetPixel(i, j, Color.FromArgb(outlineAlpha[i, j], 0, 255, 0));
                }
            }
        }

19 View Source File : HeatMapGridSquare.cs
License : GNU General Public License v3.0
Project Creator : AHeroicLlama

public Color GetColor(double largestWeight)
		{
			double localSum = GetTotalWeight();
			double alpha = localSum / largestWeight * 255;
			double redValue = weights[0] / localSum * 255;
			double blueValue = weights[1] / localSum * 255;

			return (largestWeight == 0 || localSum == 0) ?
				Color.FromArgb(0, 0, 0, 0) :
				Color.FromArgb((int)alpha, (int)redValue, 0, (int)blueValue);
		}

19 View Source File : MainWindow.xaml.cs
License : MIT License
Project Creator : ahuchjm

List<System.Drawing.Point> FindPicture(string subPic, string parPic, System.Drawing.Rectangle searchRect, byte errorRange, double matchRate = 0.9, bool isFindAll = false)
        {
            List<System.Drawing.Point> ListPoint = new List<System.Drawing.Point>();
            var subBitmap = new Bitmap(subPic);
            var parBitmap = new Bitmap(parPic);
            int subWidth = subBitmap.Width;
            int subHeight = subBitmap.Height;
            int parWidth = parBitmap.Width;
            int parHeight = parBitmap.Height;
            if (searchRect.IsEmpty)
            {
                searchRect = new System.Drawing.Rectangle(0, 0, parBitmap.Width, parBitmap.Height);
            }

            var searchLeftTop = searchRect.Location;
            var searchSize = searchRect.Size;
            System.Drawing.Color startPixelColor = subBitmap.GetPixel(0, 0);
            var subData = subBitmap.LockBits(new System.Drawing.Rectangle(0, 0, subBitmap.Width, subBitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            var parData = parBitmap.LockBits(new System.Drawing.Rectangle(0, 0, parBitmap.Width, parBitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            var byteArrarySub = new byte[subData.Stride * subData.Height];
            var byteArraryPar = new byte[parData.Stride * parData.Height];
            Marshal.Copy(subData.Scan0, byteArrarySub, 0, subData.Stride * subData.Height);
            Marshal.Copy(parData.Scan0, byteArraryPar, 0, parData.Stride * parData.Height);

            var iMax = searchLeftTop.Y + searchSize.Height - subData.Height;//行
            var jMax = searchLeftTop.X + searchSize.Width - subData.Width;//列

            int smallOffsetX = 0, smallOffsetY = 0;
            int smallStartX = 0, smallStartY = 0;
            int pointX = -1; int pointY = -1;
            for (int i = searchLeftTop.Y; i < iMax; i++)
            {
                for (int j = searchLeftTop.X; j < jMax; j++)
                {
                    //大图x,y坐标处的颜色值
                    int x = j, y = i;
                    int parIndex = i * parWidth * 4 + j * 4;
                    var colorBig = System.Drawing.Color.FromArgb(byteArraryPar[parIndex + 3], byteArraryPar[parIndex + 2], byteArraryPar[parIndex + 1], byteArraryPar[parIndex]);
                    ;
                    if (ColorAEqualColorB(colorBig, startPixelColor, errorRange))
                    {
                        smallStartX = x - smallOffsetX;//待找的图X坐标
                        smallStartY = y - smallOffsetY;//待找的图Y坐标
                        int sum = 0;//所有需要比对的有效点
                        int matchNum = 0;//成功匹配的点
                        for (int m = 0; m < subHeight; m++)
                        {
                            for (int n = 0; n < subWidth; n++)
                            {
                                int x1 = n, y1 = m;
                                int subIndex = m * subWidth * 4 + n * 4;
                                var color = System.Drawing.Color.FromArgb(byteArrarySub[subIndex + 3], byteArrarySub[subIndex + 2], byteArrarySub[subIndex + 1], byteArrarySub[subIndex]);

                                sum++;
                                int x2 = smallStartX + x1, y2 = smallStartY + y1;
                                int parReleativeIndex = y2 * parWidth * 4 + x2 * 4;//比对大图对应的像素点的颜色
                                var colorPixel = System.Drawing.Color.FromArgb(byteArraryPar[parReleativeIndex + 3], byteArraryPar[parReleativeIndex + 2], byteArraryPar[parReleativeIndex + 1], byteArraryPar[parReleativeIndex]);
                                if (ColorAEqualColorB(colorPixel, color, errorRange))
                                {
                                    matchNum++;
                                }
                            }
                        }
                        if ((double)matchNum / sum >= matchRate)
                        {
                            Console.WriteLine((double)matchNum / sum);
                            pointX = smallStartX + (int)(subWidth / 2.0);
                            pointY = smallStartY + (int)(subHeight / 2.0);
                            var point = new System.Drawing.Point(pointX, pointY);
                            if (!ListContainsPoint(ListPoint, point, 10))
                            {
                                ListPoint.Add(point);
                            }
                            if (!isFindAll)
                            {
                                goto FIND_END;
                            }
                        }
                    }
                    //小图x1,y1坐标处的颜色值
                }
            }
        FIND_END:
            subBitmap.UnlockBits(subData);
            parBitmap.UnlockBits(parData);
            subBitmap.Dispose();
            parBitmap.Dispose();
            GC.Collect();
            return ListPoint;
        }

19 View Source File : MainWindow.xaml.cs
License : MIT License
Project Creator : ahuchjm

List<NumBody> FindText(string subPic, string parPic, System.Drawing.Rectangle searchRect, byte errorRange, double matchRate = 0.9, bool isFindAll = false)
        {

            List<NumBody> ListPoint = new List<NumBody>();
            var subBitmap = new Bitmap(subPic);
            var parBitmap = new Bitmap(parPic);
            int subWidth = subBitmap.Width;
            int subHeight = subBitmap.Height;
            int parWidth = parBitmap.Width;
            int parHeight = parBitmap.Height;
            var bgColor = subBitmap.GetPixel(0, 0);//背景红色
            if (searchRect.IsEmpty)
            {
                searchRect = new System.Drawing.Rectangle(0, 0, parBitmap.Width, parBitmap.Height);
            }
            var searchLeftTop = searchRect.Location;
            var searchSize = searchRect.Size;
            var subData = subBitmap.LockBits(new System.Drawing.Rectangle(0, 0, subBitmap.Width, subBitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            var parData = parBitmap.LockBits(new System.Drawing.Rectangle(0, 0, parBitmap.Width, parBitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            var byteArrarySub = new byte[subData.Stride * subData.Height];
            var byteArraryPar = new byte[parData.Stride * parData.Height];
            Marshal.Copy(subData.Scan0, byteArrarySub, 0, subData.Stride * subData.Height);
            Marshal.Copy(parData.Scan0, byteArraryPar, 0, parData.Stride * parData.Height);
            var iMax = searchLeftTop.Y + searchSize.Height - subData.Height;//行
            var jMax = searchLeftTop.X + searchSize.Width - subData.Width;//列
            System.Drawing.Color startPixelColor = System.Drawing.Color.FromArgb(0, 0, 0);
            int smallOffsetX = 0, smallOffsetY = 0;
            int smallStartX = 0, smallStartY = 0;
            int pointX = -1; int pointY = -1;


            for (int m = 0; m < subHeight; m++)
            {
                for (int n = 0; n < subWidth; n++)
                {
                    smallOffsetX = n;
                    smallOffsetY = m;
                    int subIndex = m * subWidth * 4 + n * 4;
                    var color = System.Drawing.Color.FromArgb(byteArrarySub[subIndex + 3], byteArrarySub[subIndex + 2], byteArrarySub[subIndex + 1], byteArrarySub[subIndex]);
                    if (!ColorAEqualColorB(color, bgColor, errorRange))
                    {
                        startPixelColor = color;
                        goto END;
                    }
                }
            }

        END:
            for (int i = searchLeftTop.Y; i < iMax; i++)
            {
                for (int j = searchLeftTop.X; j < jMax; j++)
                {
                    //大图x,y坐标处的颜色值
                    int x = j, y = i;
                    int parIndex = i * parWidth * 4 + j * 4;
                    var colorBig = System.Drawing.Color.FromArgb(byteArraryPar[parIndex + 3], byteArraryPar[parIndex + 2], byteArraryPar[parIndex + 1], byteArraryPar[parIndex]);
                    ;

                    List<System.Drawing.Point> myListPoint = new List<System.Drawing.Point>();
                    if (ColorAEqualColorB(colorBig, startPixelColor, errorRange))
                    {
                        smallStartX = x - smallOffsetX;//待找的图X坐标
                        smallStartY = y - smallOffsetY;//待找的图Y坐标
                        int sum = 0;//所有需要比对的有效点
                        int matchNum = 0;//成功匹配的点
                        for (int m = 0; m < subHeight; m++)
                        {
                            for (int n = 0; n < subWidth; n++)
                            {
                                int x1 = n, y1 = m;
                                int subIndex = m * subWidth * 4 + n * 4;
                                var color = System.Drawing.Color.FromArgb(byteArrarySub[subIndex + 3], byteArrarySub[subIndex + 2], byteArrarySub[subIndex + 1], byteArrarySub[subIndex]);
                                if (color != bgColor)
                                {
                                    sum++;
                                    int x2 = smallStartX + x1, y2 = smallStartY + y1;
                                    int parReleativeIndex = y2 * parWidth * 4 + x2 * 4;//比对大图对应的像素点的颜色
                                    var colorPixel = System.Drawing.Color.FromArgb(byteArraryPar[parReleativeIndex + 3], byteArraryPar[parReleativeIndex + 2], byteArraryPar[parReleativeIndex + 1], byteArraryPar[parReleativeIndex]);
                                    if (ColorAEqualColorB(colorPixel, color, errorRange))
                                    {
                                        matchNum++;
                                    }
                                    myListPoint.Add(new System.Drawing.Point(x2, y2));
                                }
                            }
                        }

                        double rate = (double)matchNum / sum;
                        if (rate>= matchRate)
                        {
                            Console.WriteLine((double)matchNum / sum);
                            pointX = smallStartX + (int)(subWidth / 2.0);
                            pointY = smallStartY + (int)(subHeight / 2.0);
                            var point = new System.Drawing.Point(pointX, pointY);
                            if (!ListTextBodyContainsPoint(ListPoint, point, 1))
                            {
                                ListPoint.Add(new NumBody() { point = point, matchNum = matchNum,matchSum=sum, matchRate = rate, bodyCollectionPoint = myListPoint });
                            }
                            SearchNumbersByMatchNum(ref ListPoint);
                            if (!isFindAll)
                            {
                                goto FIND_END;
                            }
                        }
                    }
                    //小图x1,y1坐标处的颜色值
                }
            }
        FIND_END:
            subBitmap.UnlockBits(subData);
            parBitmap.UnlockBits(parData);
            subBitmap.Dispose();
            parBitmap.Dispose();
            GC.Collect();
            return ListPoint;
        }

19 View Source File : MainWindow.xaml.cs
License : MIT License
Project Creator : ahuchjm

System.Drawing.Point FindColor(string parPic, string searchColor, System.Drawing.Rectangle searchRect, byte errorRange = 10)
        {
            var colorX = System.Drawing.ColorTranslator.FromHtml(searchColor);
            var parBitmap = new Bitmap(parPic);
            var parData = parBitmap.LockBits(new System.Drawing.Rectangle(0, 0, parBitmap.Width, parBitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            var byteArraryPar = new byte[parData.Stride * parData.Height];
            Marshal.Copy(parData.Scan0, byteArraryPar, 0, parData.Stride * parData.Height);
            if (searchRect.IsEmpty)
            {
                searchRect = new System.Drawing.Rectangle(0, 0, parBitmap.Width, parBitmap.Height);
            }
            var searchLeftTop = searchRect.Location;
            var searchSize = searchRect.Size;
            var iMax = searchLeftTop.Y + searchSize.Height;//行
            var jMax = searchLeftTop.X + searchSize.Width;//列
            int pointX = -1; int pointY = -1;
            for (int m = searchRect.Y; m < iMax; m++)
            {
                for (int n = searchRect.X; n < jMax; n++)
                {
                    int index = m * parBitmap.Width * 4 + n * 4;
                    var color = System.Drawing.Color.FromArgb(byteArraryPar[index + 3], byteArraryPar[index + 2], byteArraryPar[index + 1], byteArraryPar[index]);
                    if (ColorAEqualColorB(color, colorX, errorRange))
                    {
                        pointX = n;
                        pointY = m;
                        goto END;
                    }
                }
            }
        END:
            parBitmap.UnlockBits(parData);
            return new System.Drawing.Point(pointX, pointY);
        }

19 View Source File : ImageColorsConverter.cs
License : GNU General Public License v3.0
Project Creator : aiportal

private ColorPalette FillPalette(ColorPalette palette, bool fTransparent)
		{
			for (uint i = 0; i < this._imgColors; i++)
			{
				uint alpha = 0xff;
				uint red = (uint)((i * 0xff) / (this._imgColors - 1));
				if ((i == 0) && fTransparent)
				{
					alpha = 0;
				}
				palette.Entries[i] = Color.FromArgb((int)alpha, (int)red, (int)red, (int)red);
			}
			return palette;
		}

19 View Source File : ImageCompression.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static void SaveGrayScale(
			Image image,
			string filename,
			uint nColors,
			bool fTransparent
			)
		{

			// GIF codec supports 256 colors maximum, monochrome minimum.
			if (nColors > 256)
				nColors = 256;
			if (nColors < 2)
				nColors = 2;

			// Make a new 8-BPP indexed bitmap that is the same size as the source image.
			int Width = image.Width;
			int Height = image.Height;

			// Always use PixelFormat8bppIndexed because that is the color
			// table-based interface to the GIF codec.
			Bitmap bitmap = new Bitmap(Width,
									Height,
									PixelFormat.Format8bppIndexed);

			// Create a color palette big enough to hold the colors you want.
			ColorPalette pal = GetColorPalette(nColors);

			// Initialize a new color table with entries that are determined
			// by some optimal palette-finding algorithm; for demonstration 
			// purposes, use a grayscale.
			for (uint i = 0; i < nColors; i++)
			{
				uint Alpha = 0xFF;                      // Colors are opaque.
				uint Intensity = i * 0xFF / (nColors - 1);    // Even distribution. 

				// The GIF encoder makes the first entry in the palette
				// that has a ZERO alpha the transparent color in the GIF.
				// Pick the first one arbitrarily, for demonstration purposes.

				if (i == 0 && fTransparent) // Make this color index...
					Alpha = 0;          // Transparent

				// Create a gray scale for demonstration purposes.
				// Otherwise, use your favorite color reduction algorithm
				// and an optimum palette for that algorithm generated here.
				// For example, a color histogram, or a median cut palette.
				pal.Entries[i] = Color.FromArgb((int)Alpha,
												(int)Intensity,
												(int)Intensity,
												(int)Intensity);
			}

			// Set the palette into the new Bitmap object.
			bitmap.Palette = pal;


			// Use GetPixel below to pull out the color data of Image.
			// Because GetPixel isn't defined on an Image, make a copy 
			// in a Bitmap instead. Make a new Bitmap that is the same size as the
			// image that you want to export. Or, try to
			// interpret the native pixel format of the image by using a LockBits
			// call. Use PixelFormat32BppARGB so you can wrap a Graphics  
			// around it.
			Bitmap BmpCopy = new Bitmap(Width,
									Height,
									PixelFormat.Format32bppArgb);
			{
				Graphics g = Graphics.FromImage(BmpCopy);

				g.PageUnit = GraphicsUnit.Pixel;

				// Transfer the Image to the Bitmap
				g.DrawImage(image, 0, 0, Width, Height);

				// g goes out of scope and is marked for garbage collection.
				// Force it, just to keep things clean.
				g.Dispose();
			}

			// Lock a rectangular portion of the bitmap for writing.
			BitmapData bitmapData;
			Rectangle rect = new Rectangle(0, 0, Width, Height);

			bitmapData = bitmap.LockBits(
				rect,
				ImageLockMode.WriteOnly,
				PixelFormat.Format8bppIndexed);

			// Write to the temporary buffer that is provided by LockBits.
			// Copy the pixels from the source image in this loop.
			// Because you want an index, convert RGB to the appropriate
			// palette index here.
			IntPtr pixels = bitmapData.Scan0;

			unsafe
			{
				// Get the pointer to the image bits.
				// This is the unsafe operation.
				byte* pBits;
				if (bitmapData.Stride > 0)
					pBits = (byte*)pixels.ToPointer();
				else
					// If the Stide is negative, Scan0 points to the last 
					// scanline in the buffer. To normalize the loop, obtain
					// a pointer to the front of the buffer that is located 
					// (Height-1) scanlines previous.
					pBits = (byte*)pixels.ToPointer() + bitmapData.Stride * (Height - 1);
				uint stride = (uint)Math.Abs(bitmapData.Stride);

				for (uint row = 0; row < Height; ++row)
				{
					for (uint col = 0; col < Width; ++col)
					{
						// Map palette indexes for a gray scale.
						// If you use some other technique to color convert,
						// put your favorite color reduction algorithm here.
						Color pixel;    // The source pixel.

						// The destination pixel.
						// The pointer to the color index byte of the
						// destination; this real pointer causes this
						// code to be considered unsafe.
						byte* p8bppPixel = pBits + row * stride + col;

						pixel = BmpCopy.GetPixel((int)col, (int)row);

						// Use luminance/chrominance conversion to get grayscale.
						// Basically, turn the image into black and white TV.
						// Do not calculate Cr or Cb because you 
						// discard the color anyway.
						// Y = Red * 0.299 + Green * 0.587 + Blue * 0.114

						// This expression is best as integer math for performance,
						// however, because GetPixel listed earlier is the slowest 
						// part of this loop, the expression is left as 
						// floating point for clarity.

						double luminance = (pixel.R * 0.299) +
							(pixel.G * 0.587) +
							(pixel.B * 0.114);

						// Gray scale is an intensity map from black to white.
						// Compute the index to the grayscale entry that
						// approximates the luminance, and then round the index.
						// Also, constrain the index choices by the number of
						// colors to do, and then set that pixel's index to the 
						// byte value.
						*p8bppPixel = (byte)(luminance * (nColors - 1) / 255 + 0.5);

					} /* end loop for col */
				} /* end loop for row */
			} /* end unsafe */

			// To commit the changes, unlock the portion of the bitmap.  
			bitmap.UnlockBits(bitmapData);

			bitmap.Save(filename, ImageFormat.Png);

			// Bitmap goes out of scope here and is also marked for
			// garbage collection.
			// Pal is referenced by bitmap and goes away.
			// BmpCopy goes out of scope here and is marked for garbage
			// collection. Force it, because it is probably quite large.
			// The same applies to bitmap.
			BmpCopy.Dispose();
			bitmap.Dispose();
		}

19 View Source File : ImageCompression.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static Image GrayScaleCompress(Image image)
		{
			uint nColors = 256;
			bool fTransparent = true;

			// Make a new 8-BPP indexed bitmap that is the same size as the source image.
			int Width = image.Width;
			int Height = image.Height;

			// Always use PixelFormat8bppIndexed because that is the color
			// table-based interface to the GIF codec.
			Bitmap bitmap = new Bitmap(Width,
									Height,
									PixelFormat.Format8bppIndexed);

			// Create a color palette big enough to hold the colors you want.
			ColorPalette pal = GetColorPalette(nColors);

			// Initialize a new color table with entries that are determined
			// by some optimal palette-finding algorithm; for demonstration 
			// purposes, use a grayscale.
			for (uint i = 0; i < nColors; i++)
			{
				uint Alpha = 0xFF;                      // Colors are opaque.
				uint Intensity = i * 0xFF / (nColors - 1);    // Even distribution. 

				// The GIF encoder makes the first entry in the palette
				// that has a ZERO alpha the transparent color in the GIF.
				// Pick the first one arbitrarily, for demonstration purposes.

				if (i == 0 && fTransparent) // Make this color index...
					Alpha = 0;          // Transparent

				// Create a gray scale for demonstration purposes.
				// Otherwise, use your favorite color reduction algorithm
				// and an optimum palette for that algorithm generated here.
				// For example, a color histogram, or a median cut palette.
				pal.Entries[i] = Color.FromArgb((int)Alpha,
												(int)Intensity,
												(int)Intensity,
												(int)Intensity);
			}

			// Set the palette into the new Bitmap object.
			bitmap.Palette = pal;


			// Use GetPixel below to pull out the color data of Image.
			// Because GetPixel isn't defined on an Image, make a copy 
			// in a Bitmap instead. Make a new Bitmap that is the same size as the
			// image that you want to export. Or, try to
			// interpret the native pixel format of the image by using a LockBits
			// call. Use PixelFormat32BppARGB so you can wrap a Graphics  
			// around it.
			Bitmap BmpCopy = new Bitmap(Width,
									Height,
									PixelFormat.Format32bppArgb);
			{
				Graphics g = Graphics.FromImage(BmpCopy);

				g.PageUnit = GraphicsUnit.Pixel;

				// Transfer the Image to the Bitmap
				g.DrawImage(image, 0, 0, Width, Height);

				// g goes out of scope and is marked for garbage collection.
				// Force it, just to keep things clean.
				g.Dispose();
			}

			// Lock a rectangular portion of the bitmap for writing.
			BitmapData bitmapData;
			Rectangle rect = new Rectangle(0, 0, Width, Height);

			bitmapData = bitmap.LockBits(
				rect,
				ImageLockMode.WriteOnly,
				PixelFormat.Format8bppIndexed);

			// Write to the temporary buffer that is provided by LockBits.
			// Copy the pixels from the source image in this loop.
			// Because you want an index, convert RGB to the appropriate
			// palette index here.
			IntPtr pixels = bitmapData.Scan0;

			unsafe
			{
				// Get the pointer to the image bits.
				// This is the unsafe operation.
				byte* pBits;
				if (bitmapData.Stride > 0)
					pBits = (byte*)pixels.ToPointer();
				else
					// If the Stide is negative, Scan0 points to the last 
					// scanline in the buffer. To normalize the loop, obtain
					// a pointer to the front of the buffer that is located 
					// (Height-1) scanlines previous.
					pBits = (byte*)pixels.ToPointer() + bitmapData.Stride * (Height - 1);
				uint stride = (uint)Math.Abs(bitmapData.Stride);

				for (uint row = 0; row < Height; ++row)
				{
					for (uint col = 0; col < Width; ++col)
					{
						// Map palette indexes for a gray scale.
						// If you use some other technique to color convert,
						// put your favorite color reduction algorithm here.
						Color pixel;    // The source pixel.

						// The destination pixel.
						// The pointer to the color index byte of the
						// destination; this real pointer causes this
						// code to be considered unsafe.
						byte* p8bppPixel = pBits + row * stride + col;

						pixel = BmpCopy.GetPixel((int)col, (int)row);

						// Use luminance/chrominance conversion to get grayscale.
						// Basically, turn the image into black and white TV.
						// Do not calculate Cr or Cb because you 
						// discard the color anyway.
						// Y = Red * 0.299 + Green * 0.587 + Blue * 0.114

						// This expression is best as integer math for performance,
						// however, because GetPixel listed earlier is the slowest 
						// part of this loop, the expression is left as 
						// floating point for clarity.

						double luminance = (pixel.R * 0.299) +
							(pixel.G * 0.587) +
							(pixel.B * 0.114);

						// Gray scale is an intensity map from black to white.
						// Compute the index to the grayscale entry that
						// approximates the luminance, and then round the index.
						// Also, constrain the index choices by the number of
						// colors to do, and then set that pixel's index to the 
						// byte value.
						*p8bppPixel = (byte)(luminance * (nColors - 1) / 255 + 0.5);

					} /* end loop for col */
				} /* end loop for row */
			} /* end unsafe */

			// To commit the changes, unlock the portion of the bitmap.  
			bitmap.UnlockBits(bitmapData);

			// Bitmap goes out of scope here and is also marked for
			// garbage collection.
			// Pal is referenced by bitmap and goes away.
			// BmpCopy goes out of scope here and is marked for garbage
			// collection. Force it, because it is probably quite large.
			// The same applies to bitmap.
			BmpCopy.Dispose();
			//bitmap.Dispose();
			return bitmap;
		}

19 View Source File : ImageCompression.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static Image GrayScale(Image image)
		{
			// Make a new 8-BPP indexed bitmap that is the same size as the source image.
			int Width = image.Width;
			int Height = image.Height;
			int nColors = 256;
			Bitmap bitmap = new Bitmap(Width, Height, PixelFormat.Format8bppIndexed);

			// fill palette
			ColorPalette pal = bitmap.Palette;
			for (int i = 0; i < nColors; i++)
			{
				int Alpha = (i == 0) ? 0x00 : 0xFF;
				int Intensity = i * 0xFF / (nColors - 1);
				pal.Entries[i] = Color.FromArgb(Alpha, Intensity, Intensity, Intensity);
			}

			Rectangle rect = new Rectangle(0, 0, Width, Height);

			BitmapData bitmapData = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

			// Write to the temporary buffer that is provided by LockBits.
			// Copy the pixels from the source image in this loop.
			// Because you want an index, convert RGB to the appropriate
			// palette index here.
			IntPtr pixels = bitmapData.Scan0;

			unsafe
			{
				// Get the pointer to the image bits.
				// This is the unsafe operation.
				byte* pBits;
				if (bitmapData.Stride > 0)
					pBits = (byte*)pixels.ToPointer();
				else
					// If the Stide is negative, Scan0 points to the last 
					// scanline in the buffer. To normalize the loop, obtain
					// a pointer to the front of the buffer that is located 
					// (Height-1) scanlines previous.
					pBits = (byte*)pixels.ToPointer() + bitmapData.Stride * (Height - 1);
				uint stride = (uint)Math.Abs(bitmapData.Stride);

				for (uint row = 0; row < Height; ++row)
				{
					for (uint col = 0; col < Width; ++col)
					{
						//Color pixel;    // The source pixel.

						// The destination pixel.
						// The pointer to the color index byte of the
						// destination; this real pointer causes this
						// code to be considered unsafe.
						byte* p8bppPixel = pBits + row * stride + col;

						//pixel = image.GetPixel((int)col, (int)row);

						// Use luminance/chrominance conversion to get grayscale.
						// Basically, turn the image into black and white TV.
						// Do not calculate Cr or Cb because you 
						// discard the color anyway.
						// Y = Red * 0.299 + Green * 0.587 + Blue * 0.114

						// This expression is best as integer math for performance,
						// however, because GetPixel listed earlier is the slowest 
						// part of this loop, the expression is left as 
						// floating point for clarity.

						//double luminance = (pixel.R * 0.299) +
						//    (pixel.G * 0.587) +
						//    (pixel.B * 0.114);

						// Gray scale is an intensity map from black to white.
						// Compute the index to the grayscale entry that
						// approximates the luminance, and then round the index.
						// Also, constrain the index choices by the number of
						// colors to do, and then set that pixel's index to the 
						// byte value.
						//*p8bppPixel = (byte)(luminance * (nColors - 1) / 255 + 0.5);

					} /* end loop for col */
				} /* end loop for row */
			} /* end unsafe */

			// To commit the changes, unlock the portion of the bitmap.  
			bitmap.UnlockBits(bitmapData);

			// Bitmap goes out of scope here and is also marked for
			// garbage collection.
			// Pal is referenced by bitmap and goes away.
			// BmpCopy goes out of scope here and is marked for garbage
			// collection. Force it, because it is probably quite large.
			// The same applies to bitmap.
			bitmap.Dispose();
			return null;
		}

19 View Source File : ImageCompression.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static void SaveGrayScale(Image image, string filename, uint nColors, bool fTransparent)
		{

			// GIF codec supports 256 colors maximum, monochrome minimum.
			if (nColors > 256)
				nColors = 256;
			if (nColors < 2)
				nColors = 2;

			// Make a new 8-BPP indexed bitmap that is the same size as the source image.
			int Width = image.Width;
			int Height = image.Height;

			// Always use PixelFormat8bppIndexed because that is the color
			// table-based interface to the GIF codec.
			Bitmap bitmap = new Bitmap(Width,
									Height,
									PixelFormat.Format8bppIndexed);

			// Create a color palette big enough to hold the colors you want.
			ColorPalette pal = GetColorPalette(nColors);

			// Initialize a new color table with entries that are determined
			// by some optimal palette-finding algorithm; for demonstration 
			// purposes, use a grayscale.
			for (uint i = 0; i < nColors; i++)
			{
				uint Alpha = 0xFF;                      // Colors are opaque.
				uint Intensity = i * 0xFF / (nColors - 1);    // Even distribution. 

				// The GIF encoder makes the first entry in the palette
				// that has a ZERO alpha the transparent color in the GIF.
				// Pick the first one arbitrarily, for demonstration purposes.

				if (i == 0 && fTransparent) // Make this color index...
					Alpha = 0;          // Transparent

				// Create a gray scale for demonstration purposes.
				// Otherwise, use your favorite color reduction algorithm
				// and an optimum palette for that algorithm generated here.
				// For example, a color histogram, or a median cut palette.
				pal.Entries[i] = Color.FromArgb((int)Alpha,
												(int)Intensity,
												(int)Intensity,
												(int)Intensity);
			}

			// Set the palette into the new Bitmap object.
			bitmap.Palette = pal;


			// Use GetPixel below to pull out the color data of Image.
			// Because GetPixel isn't defined on an Image, make a copy 
			// in a Bitmap instead. Make a new Bitmap that is the same size as the
			// image that you want to export. Or, try to
			// interpret the native pixel format of the image by using a LockBits
			// call. Use PixelFormat32BppARGB so you can wrap a Graphics  
			// around it.
			Bitmap BmpCopy = new Bitmap(Width,
									Height,
									PixelFormat.Format32bppArgb);
			{
				Graphics g = Graphics.FromImage(BmpCopy);

				g.PageUnit = GraphicsUnit.Pixel;

				// Transfer the Image to the Bitmap
				g.DrawImage(image, 0, 0, Width, Height);

				// g goes out of scope and is marked for garbage collection.
				// Force it, just to keep things clean.
				g.Dispose();
			}

			// Lock a rectangular portion of the bitmap for writing.
			BitmapData bitmapData;
			Rectangle rect = new Rectangle(0, 0, Width, Height);

			bitmapData = bitmap.LockBits(
				rect,
				ImageLockMode.WriteOnly,
				PixelFormat.Format8bppIndexed);

			// Write to the temporary buffer that is provided by LockBits.
			// Copy the pixels from the source image in this loop.
			// Because you want an index, convert RGB to the appropriate
			// palette index here.
			IntPtr pixels = bitmapData.Scan0;

			unsafe
			{
				// Get the pointer to the image bits.
				// This is the unsafe operation.
				byte* pBits;
				if (bitmapData.Stride > 0)
					pBits = (byte*)pixels.ToPointer();
				else
					// If the Stide is negative, Scan0 points to the last 
					// scanline in the buffer. To normalize the loop, obtain
					// a pointer to the front of the buffer that is located 
					// (Height-1) scanlines previous.
					pBits = (byte*)pixels.ToPointer() + bitmapData.Stride * (Height - 1);
				uint stride = (uint)Math.Abs(bitmapData.Stride);

				for (uint row = 0; row < Height; ++row)
				{
					for (uint col = 0; col < Width; ++col)
					{
						// Map palette indexes for a gray scale.
						// If you use some other technique to color convert,
						// put your favorite color reduction algorithm here.
						Color pixel;    // The source pixel.

						// The destination pixel.
						// The pointer to the color index byte of the
						// destination; this real pointer causes this
						// code to be considered unsafe.
						byte* p8bppPixel = pBits + row * stride + col;

						pixel = BmpCopy.GetPixel((int)col, (int)row);

						// Use luminance/chrominance conversion to get grayscale.
						// Basically, turn the image into black and white TV.
						// Do not calculate Cr or Cb because you 
						// discard the color anyway.
						// Y = Red * 0.299 + Green * 0.587 + Blue * 0.114

						// This expression is best as integer math for performance,
						// however, because GetPixel listed earlier is the slowest 
						// part of this loop, the expression is left as 
						// floating point for clarity.

						double luminance = (pixel.R * 0.299) +
							(pixel.G * 0.587) +
							(pixel.B * 0.114);

						// Gray scale is an intensity map from black to white.
						// Compute the index to the grayscale entry that
						// approximates the luminance, and then round the index.
						// Also, constrain the index choices by the number of
						// colors to do, and then set that pixel's index to the 
						// byte value.
						*p8bppPixel = (byte)(luminance * (nColors - 1) / 255 + 0.5);

					} /* end loop for col */
				} /* end loop for row */
			} /* end unsafe */

			// To commit the changes, unlock the portion of the bitmap.  
			bitmap.UnlockBits(bitmapData);

			bitmap.Save(filename, ImageFormat.Png);

			// Bitmap goes out of scope here and is also marked for
			// garbage collection.
			// Pal is referenced by bitmap and goes away.
			// BmpCopy goes out of scope here and is marked for garbage
			// collection. Force it, because it is probably quite large.
			// The same applies to bitmap.
			BmpCopy.Dispose();
			bitmap.Dispose();
		}

19 View Source File : Toolbox.cs
License : GNU General Public License v3.0
Project Creator : akaAgar

public static Color? GetColorFromString(string colorString)
        {
            int r, g, b;

            try
            {
                colorString = colorString.Trim();


                if (colorString.StartsWith("#")) // HTML format
                {
                    colorString = colorString.Substring(1);

                    if (colorString.Length == 6)
                    {
                        r = Convert.ToInt32(colorString.Substring(0, 2), 16);
                        g = Convert.ToInt32(colorString.Substring(2, 2), 16);
                        b = Convert.ToInt32(colorString.Substring(4, 2), 16);

                        return Color.FromArgb(255, r, g, b);
                    }
                    else if (colorString.Length == 3)
                    {
                        string xR = colorString.Substring(0, 1); xR += xR;
                        string xG = colorString.Substring(1, 1); xG += xG;
                        string xB = colorString.Substring(2, 1); xB += xB;

                        r = Convert.ToInt32(xR, 16);
                        g = Convert.ToInt32(xG, 16);
                        b = Convert.ToInt32(xB, 16);

                        return Color.FromArgb(255, r, g, b);
                    }
                }
                else if (colorString.Contains(",")) // R,G,B format
                {
                    string[] rgbStrings = colorString.Split(',');

                    if (rgbStrings.Length >= 3)
                    {
                        r = Convert.ToInt32(rgbStrings[0].Trim());
                        g = Convert.ToInt32(rgbStrings[1].Trim());
                        b = Convert.ToInt32(rgbStrings[2].Trim());

                        return Color.FromArgb(255, r, g, b);
                    }
                }
                else if (Enum.TryParse(colorString, true, out KnownColor knownColor))
                    return Color.FromKnownColor(knownColor);
            }
            catch (Exception)
            {
                return null;
            }

            return null;
        }

19 View Source File : BitmapExtensions.cs
License : MIT License
Project Creator : AlexanderPro

public static Bitmap Dark(this Bitmap bitmap)
        {
            var newBitmap = new Bitmap(bitmap.Width, bitmap.Height);

            using (var graphics = Graphics.FromImage(newBitmap))
            {
                graphics.DrawImage(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height), new Rectangle(0, 0, bitmap.Width, bitmap.Height), GraphicsUnit.Pixel);
                var brush = new SolidBrush(Color.FromArgb(200, 0, 0, 0));
                graphics.FillRectangle(brush, 0, 0, bitmap.Width, bitmap.Height);
            }

            return newBitmap;
        }

19 View Source File : GifDecoder.cs
License : MIT License
Project Creator : AlexGyver

private void SetPixels() 
		{
			// expose destination image's pixels as int array
			//		int[] dest =
			//			(( int ) image.getRaster().getDataBuffer()).getData();
			int[] dest = GetPixels( bitmap );

			// fill in starting image contents based on last image's dispose code
			if (lastDispose > 0) 
			{
				if (lastDispose == 3) 
				{
					// use image before last
					int n = frameCount - 2;
					if (n > 0) 
					{
						lastImage = GetFrame(n - 1).Image;
					} 
					else 
					{
						lastImage = null;
					}
				}

				if (lastImage != null) 
				{
					//				int[] prev =
					//					((DataBufferInt) lastImage.getRaster().getDataBuffer()).getData();
					int[] prev = GetPixels( new Bitmap( lastImage ) );
					Array.Copy(prev, 0, dest, 0, width * height);
					// copy pixels

					if (lastDispose == 2) 
					{
						// fill last image rect area with background color
						Graphics g = Graphics.FromImage( image );
						Color c = Color.Empty;
						if (transparency) 
						{
							c = Color.FromArgb( 0, 0, 0, 0 ); 	// replacedume background is transparent
						} 
						else 
						{
							c = Color.FromArgb( lastBgColor ) ;
							//						c = new Color(lastBgColor); // use given background color
						}
						Brush brush = new SolidBrush( c );
						g.FillRectangle( brush, lastRect );
						brush.Dispose();
						g.Dispose();
					}
				}
			}

			// copy each source line to the appropriate place in the destination
			int preplaced = 1;
			int inc = 8;
			int iline = 0;
			for (int i = 0; i < ih; i++) 
			{
				int line = i;
				if (interlace) 
				{
					if (iline >= ih) 
					{
						preplaced++;
						switch (preplaced) 
						{
							case 2 :
								iline = 4;
								break;
							case 3 :
								iline = 2;
								inc = 4;
								break;
							case 4 :
								iline = 1;
								inc = 2;
								break;
						}
					}
					line = iline;
					iline += inc;
				}
				line += iy;
				if (line < height) 
				{
					int k = line * width;
					int dx = k + ix; // start of line in dest
					int dlim = dx + iw; // end of dest line
					if ((k + width) < dlim) 
					{
						dlim = k + width; // past dest edge
					}
					int sx = i * iw; // start of line in source
					while (dx < dlim) 
					{
						// map color and insert in destination
						int index = ((int) pixels[sx++]) & 0xff;
						int c = act[index];
						if (c != 0) 
						{
							dest[dx] = c;
						}
						dx++;
					}
				}
			}
			SetPixels( dest );
		}

19 View Source File : ConverterExtensions.cs
License : MIT License
Project Creator : AlexGyver

public static Color ToColor(this OxyColor c)
        {
            return Color.FromArgb(c.A, c.R, c.G, c.B);
        }

19 View Source File : PlotControl.cs
License : MIT License
Project Creator : AlexGyver

protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            var rc = new GraphicsRenderContext(this, e.Graphics, e.ClipRectangle);
            if (model != null)
                model.Render(rc);
            if (zoomRectangle != Rectangle.Empty)
            {
                using (var zoomBrush = new SolidBrush(Color.FromArgb(0x40, 0xFF, 0xFF, 0x00)))
                using (var zoomPen = new Pen(Color.Black))
                {
                    zoomPen.DashPattern = new float[] { 3, 1 };
                    e.Graphics.FillRectangle(zoomBrush, zoomRectangle);
                    e.Graphics.DrawRectangle(zoomPen, zoomRectangle);
                }
            }
        }

19 View Source File : Plot.cs
License : MIT License
Project Creator : AlexGyver

protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            try
            {
                lock (this.invalidateLock)
                {
                    if (this.isModelInvalidated)
                    {
                        if (this.model != null)
                        {
                            this.model.Update(this.updateDataFlag);
                            this.updateDataFlag = false;
                        }

                        this.isModelInvalidated = false;
                    }
                }

                lock (this.renderingLock)
                {
                    this.renderContext.SetGraphicsTarget(e.Graphics);
                    if (this.model != null)
                    {
                        this.model.Render(this.renderContext, this.Width, this.Height);
                    }

                    if (this.zoomRectangle != Rectangle.Empty)
                    {
                        using (var zoomBrush = new SolidBrush(Color.FromArgb(0x40, 0xFF, 0xFF, 0x00)))
                        using (var zoomPen = new Pen(Color.Black))
                        {
                            zoomPen.DashPattern = new float[] { 3, 1 };
                            e.Graphics.FillRectangle(zoomBrush, this.zoomRectangle);
                            e.Graphics.DrawRectangle(zoomPen, this.zoomRectangle);
                        }
                    }
                }
            }
            catch (Exception paintException)
            {
                var trace = new StackTrace(paintException);
                Debug.WriteLine(paintException);
                Debug.WriteLine(trace);
                using (var font = new Font("Arial", 10))
                {
                    e.Graphics.DrawString(
                        "OxyPlot paint exception: " + paintException.Message, font, Brushes.Red, 10, 10);
                }
            }
        }

19 View Source File : GraphicsRenderContext.cs
License : MIT License
Project Creator : AlexGyver

private Color ToColor(OxyColor c)
        {
            return Color.FromArgb(c.A, c.R, c.G, c.B);
        }

19 View Source File : AnnotationDrawControl.cs
License : MIT License
Project Creator : AlturosDestinations

private void DrawLabel(Graphics graphics, float x, float y, ObjectClreplaced objectClreplaced)
        {
            if (objectClreplaced == null || !this.ShowLabels)
            {
                return;
            }

            using (var brush = new SolidBrush(DrawHelper.GetColorCode(objectClreplaced.Id)))
            using (var bgBrush = new SolidBrush(Color.FromArgb(128, 255, 255, 255)))
            using (var font = new Font("Arial", 12))
            {
                var text = $"{objectClreplaced.Id} {objectClreplaced.Name}";
                var point = new PointF(x + 4, y + 4);
                var size = graphics.MeasureString(text, font);

                graphics.FillRectangle(bgBrush, point.X, point.Y, size.Width, size.Height);
                graphics.DrawString(text, font, brush, point);
            }
        }

19 View Source File : Main.cs
License : MIT License
Project Creator : AlturosDestinations

private void DrawBoundingBoxes(List<YoloItem> items, YoloItem selectedItem = null)
        {
            var imageInfo = this.GetCurrentImage();
            //Load the image(probably from your stream)
            var image = Image.FromFile(imageInfo.Path);

            using (var canvas = Graphics.FromImage(image))
            {
                foreach (var item in items)
                {
                    var x = item.X;
                    var y = item.Y;
                    var width = item.Width;
                    var height = item.Height;
                    
                    var brush = this.GetBrush(item.Confidence);
                    var penSize = image.Width / 100.0f;

                    using (var pen = new Pen(brush, penSize))
                    using (var overlayBrush = new SolidBrush(Color.FromArgb(150, 255, 255, 102)))
                    {
                        if (item.Equals(selectedItem))
                        {
                            canvas.FillRectangle(overlayBrush, x, y, width, height);
                        }

                        canvas.DrawRectangle(pen, x, y, width, height);
                    }
                }

                canvas.Flush();
            }

            var oldImage = this.pictureBox1.Image;
            this.pictureBox1.Image = image;
            oldImage?.Dispose();
        }

19 View Source File : AnnotationDrawControl.cs
License : MIT License
Project Creator : AlturosDestinations

private void PictureBox1_Paint(object sender, PaintEventArgs e)
        {
            if (this.rotatingPictureBox.Image == null)
            {
                return;
            }

            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            e.Graphics.InterpolationMode = InterpolationMode.High;

            var drawOffset = this._mouseDragElementSize / 2;

            if (this._mouseOver)
            {
                e.Graphics.DrawLine(Pens.Blue, new Point(this._mousePosition.X, this.rotatingPictureBox.Top), new Point(this._mousePosition.X, this.rotatingPictureBox.Bottom));
                e.Graphics.DrawLine(Pens.Blue, new Point(this.rotatingPictureBox.Left, this._mousePosition.Y), new Point(this.rotatingPictureBox.Right, this._mousePosition.Y));
            }

            var boundingBoxes = this._annotationImage?.BoundingBoxes;
            if (boundingBoxes != null)
            {
                var canHighlightBoundingBox = true;
                var canHighlightDragPoint = true;

                var orderedBoundingBoxes = this.OrderBoundingBoxes(boundingBoxes);

                foreach (var boundingBox in orderedBoundingBoxes)
                {
                    var rectangle = this.GetRectangle(boundingBox);
                    var brush = DrawHelper.GetColorCode(boundingBox.ObjectIndex);
                    var objectClreplaced = this._objectClreplacedes.FirstOrDefault(o => o.Id == boundingBox.ObjectIndex);

                    using (var pen = new Pen(brush, 2))
                    {
                        e.Graphics.DrawRectangle(pen, rectangle);
                    }
                    if (this._selectedBoundingBox == boundingBox)
                    {
                        e.Graphics.DrawRectangle(Pens.Yellow, Rectangle.Inflate(rectangle, 2, 2));
                    }

                    this.DrawLabel(e.Graphics, rectangle.X, rectangle.Y, objectClreplaced);

                    var biggerRectangle = Rectangle.Inflate(rectangle, 20, 20);
                    if ((this._draggedBoundingBox == null && biggerRectangle.Contains(this._mousePosition)) || this._draggedBoundingBox == boundingBox)
                    {
                        if (canHighlightBoundingBox)
                        {
                            System.Windows.Forms.Cursor.Current = Cursors.SizeAll;
                            canHighlightBoundingBox = false;
                        }
                        else
                        {
                            continue;
                        }

                        if (this._selectedBoundingBox != boundingBox)
                        {
                            e.Graphics.DrawRectangle(Pens.Pink, Rectangle.Inflate(rectangle, 2, 2));
                        }

                        var dragPoints = this.GetDragPoints(rectangle, drawOffset);

                        foreach (var dragPoint in dragPoints)
                        {
                            var dragElementBrush = Brushes.LightPink;

                            if (this.PointDistance(this._mousePosition, new Point(dragPoint.Point.X, dragPoint.Point.Y)) < this._maxMouseDistanceToDragPoint && canHighlightDragPoint)
                            {
                                System.Windows.Forms.Cursor.Current = dragPoint.Cursor;
                                dragElementBrush = Brushes.Yellow;

                                canHighlightBoundingBox = false;
                                canHighlightDragPoint = false;
                            }

                            if (dragPoint.Type == DragPointType.Resize)
                            {
                                // Make horizontal/vertical anchors smaller
                                var size = (dragPoint.Angle % 90 == 0) ? 6.5f : 10;

                                var points = new PointF[]
                                {
                                    new PointF(
                                        dragPoint.Point.X + (float)Math.Cos(MathHelper.Deg2Rad * (dragPoint.Angle - 90)) * size,
                                        dragPoint.Point.Y - (float)Math.Sin(MathHelper.Deg2Rad * (dragPoint.Angle - 90)) * size),
                                    new PointF(
                                        dragPoint.Point.X + (float)Math.Cos(MathHelper.Deg2Rad * (dragPoint.Angle + 180)) * size,
                                        dragPoint.Point.Y - (float)Math.Sin(MathHelper.Deg2Rad * (dragPoint.Angle + 180)) * size),
                                    new PointF(
                                        dragPoint.Point.X + (float)Math.Cos(MathHelper.Deg2Rad * (dragPoint.Angle + 90)) * size,
                                        dragPoint.Point.Y - (float)Math.Sin(MathHelper.Deg2Rad * (dragPoint.Angle + 90)) * size),
                                };

                                e.Graphics.FillPolygon(dragElementBrush, points);
                            }
                            else if (dragPoint.Type == DragPointType.Delete)
                            {
                                e.Graphics.FillEllipse(Brushes.Red, dragPoint.Point.X - this._mouseDragElementSize / 3, dragPoint.Point.Y - this._mouseDragElementSize / 3, this._mouseDragElementSize * 1.5f, this._mouseDragElementSize * 1.5f);

                                using (var pen = new Pen(Brushes.White, 4))
                                {
                                    var centerX = dragPoint.Point.X + this._mouseDragElementSize / 2;
                                    var centerY = dragPoint.Point.Y + this._mouseDragElementSize / 2;
                                    e.Graphics.DrawLine(pen, new Point(centerX - 4, centerY - 4), new Point(centerX + 4, centerY + 4));
                                    e.Graphics.DrawLine(pen, new Point(centerX + 4, centerY - 4), new Point(centerX - 4, centerY + 4));
                                }
                            }
                            else
                            {
                                e.Graphics.FillEllipse(dragElementBrush, dragPoint.Point.X, dragPoint.Point.Y, this._mouseDragElementSize, this._mouseDragElementSize);
                            }
                        }

                        canHighlightDragPoint = false;
                    }
                }
            }

            if (this._createBoundingBox)
            {
                var point1 = this._creationPoint;
                var point2 = this._mousePosition;

                var topLeftCorner = new PointF((int)Math.Min(point1.X, point2.X), (int)Math.Min(point1.Y, point2.Y));
                var bottomRightCorner = new PointF((int)Math.Max(point1.X, point2.X), (int)Math.Max(point1.Y, point2.Y));

                topLeftCorner = this.ClampPoint(topLeftCorner);
                bottomRightCorner = this.ClampPoint(bottomRightCorner);

                // TODO: Place this outside of painting since this isn't just used for drawing
                this._canPlaceBoundingBox = true;
                if (bottomRightCorner.X - topLeftCorner.X < this._minSize.Width || bottomRightCorner.Y - topLeftCorner.Y < this._minSize.Height)
                {
                    this._canPlaceBoundingBox = false;
                }

                using (var pen = new Pen(this._canPlaceBoundingBox ? Color.FromArgb(255, 255, 255, 0) : Color.FromArgb(255, 255, 191, 0)))
                {
                    e.Graphics.DrawRectangle(pen,
                        new Rectangle(
                            new Point((int)topLeftCorner.X, (int)topLeftCorner.Y),
                            new Size((int)(bottomRightCorner.X - topLeftCorner.X), (int)(bottomRightCorner.Y - topLeftCorner.Y))));

                    if (!this._canPlaceBoundingBox)
                    {
                        e.Graphics.DrawLine(pen, topLeftCorner, bottomRightCorner);
                        e.Graphics.DrawLine(pen, new PointF(topLeftCorner.X, bottomRightCorner.Y), new PointF(bottomRightCorner.X, topLeftCorner.Y));
                    }
                }
            }
        }

19 View Source File : ThemingService.cs
License : Apache License 2.0
Project Creator : AmpScm

public Color GetThemedColorValue(ref Guid colorCategory, string colorName, bool foreground)
        {
            Type vsUIShell5 = typeof(IVsUIShell5);

            if (vsUIShell5 == null)
                throw new InvalidOperationException();

            IVsUIShell5 vs5 = GetService<IVsUIShell5>(typeof(SVsUIShell));
            MethodInfo method = vsUIShell5.GetMethod("GetThemedColor");
            
            uint clr = vs5.GetThemedColor(ref colorCategory, colorName, foreground ? (uint)1 : 0);
            // TODO: Use bitshifting

            byte[] colorComponents = BitConverter.GetBytes(clr);
            return System.Drawing.Color.FromArgb(colorComponents[3], colorComponents[0], colorComponents[1], colorComponents[2]);
        }

19 View Source File : Program.cs
License : Apache License 2.0
Project Creator : AmpScm

static void Run(string[] args)
        {
            List<string> argList = new List<string>(args);
            bool _transparentHack = false;
            while (argList.Count > 0 && argList[0].StartsWith("-"))
            {
                string arg = argList[0];
                if (arg == "--")
                {
                    argList.RemoveAt(0);
                    break;
                }
                switch (arg)
                {
                    case "-th":
                        _transparentHack = true;
                        break;
                    default:
                        Console.Error.WriteLine("Unhandled argument {0}", arg);
                        Environment.Exit(1);
                        break;
                }
                argList.RemoveAt(0);
            }

            if (argList.Count < 2)
            {
                Console.Error.WriteLine("Required argument missing");
                Console.Error.WriteLine("BitmapExtractor [-th] <replacedembly> <dir>");
                Environment.Exit(1);
            }
            string from = argList[0];
            string dir = argList[1];

            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);

            CommandTable table = new CommandTable();

            Console.WriteLine("Dumping bitmaps in {0} to {1}:", from, dir);

            replacedembly asm = null;
            try
            {
                asm = replacedembly.LoadFile(from);
            }
            catch { }


            try
            {
                if (asm != null
                    ? !table.Read(replacedembly.LoadFile(from), new ReadErrorHandler())
                    : !table.Read(from, new ReadErrorHandler()))
                {
                    Console.Error.WriteLine("* Loading failed, exiting *");
                    Environment.Exit(1);
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                Environment.Exit(1);
            }

            BitmapItemList bitmaps = table.GetBitmapList();

            foreach (BitmapItem bi in bitmaps)
            {
                uint resourceId = bi.IDResource;
                Dictionary<uint, int> map = new Dictionary<uint, int>();
                Color transparentColor = Color.FromArgb(0xFF, 0xFF, 0, 0xFF);
                bool haveColor = false;

                for (int i = 0; i < bi.UsedSlots.Length; i++)
                {
                    map[bi.UsedSlots[i]] = i;
                    if (_transparentHack && !haveColor && bi.UsedSlots[i] == 1)
                    {
                        Bitmap bm = bitmaps.GetBitmap(bi.GID, bi.UsedSlots[i]);
                        transparentColor = bm.GetPixel(0, 0);
                        Console.WriteLine("Found color: {0}", transparentColor);
                        haveColor = true;
                    }
                }

                ButtonList bl = table.GetButtonList();

                foreach (CommandButton cb in table.GetButtonList())
                {
                    if (cb.IconGID != bi.GID)
                        continue;

                    Bitmap bm = bitmaps.GetBitmap(cb.IconGID, cb.IconIndex);
                    string name = cb.CanonicalName.Trim(' ', '.', '\t', '&').Replace(" ", "").Replace("&", "");

                    if (bm == null)
                    {
                        Console.WriteLine("Couldn't get icon for {0}", name);
                        continue;
                    }

                    if (_transparentHack)
                        bm.MakeTransparent(transparentColor);

                    try
                    {
                        bm.Save(Path.Combine(dir, name + ".png"), ImageFormat.Png);
                        Console.WriteLine("Writing {0}. Succeeded", name);
                    }
                    catch
                    {
                        Console.WriteLine("Writing {0}. Failed", name);
                    }
                }
            }
            Console.WriteLine("Done");
        }

19 View Source File : ClearTypeLetterGlyph.cs
License : Apache License 2.0
Project Creator : anmcgrath

public static ClearTypeLetterGlyph CreateGlyph(GlyphTypeface glyphTypeface, System.Drawing.Font font, double size, char ch, Color fontColor, Color bgColor)
        {
            if (ch == ' ') return CreateSpaceGlyph(glyphTypeface, size);

            int width;
            int height;

            using (var bmp1 = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppPArgb))
            {
                using (var g = Graphics.FromImage(bmp1))
                {
                    //var sizef = g.MeasureString("" + ch, font, new PointF(0, 0), StringFormat.GenericTypographic);
                    var sizef = g.MeasureString("" + ch, font, new PointF(0, 0), StringFormat.GenericTypographic);
                    width = (int) Math.Ceiling(sizef.Width);
                    height = (int) Math.Ceiling(sizef.Height);
                }
            }

            if (width == 0 || height == 0) return null;

            var res = new List<Item>();

            using (var bmp = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb))
            {
                var fg2 = System.Drawing.Color.FromArgb(fontColor.A, fontColor.R, fontColor.G, fontColor.B);
                var bg2 = System.Drawing.Color.FromArgb(bgColor.A, bgColor.R, bgColor.G, bgColor.B);

                using (var g = System.Drawing.Graphics.FromImage(bmp))
                {
                    g.FillRectangle(new System.Drawing.SolidBrush(bg2), new Rectangle(0, 0, width, height));
                    g.DrawString("" + ch, font, new System.Drawing.SolidBrush(fg2), 0, 0, StringFormat.GenericTypographic);
                }

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        var color = bmp.GetPixel(x, y);
                        if (color != bg2)
                        {
                            res.Add(new Item
                            {
                                X = (short)x,
                                Y = (short)y,
                                Color = WriteableBitmapExtensions.ConvertColor(Color.FromArgb(color.A, color.R, color.G, color.B)),
                            });
                        }
                    }
                }
            }

            //var res = new List<int>();

            //using (var bmp = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb))
            //{
            //    var fg2 = System.Drawing.Color.FromArgb(fontColor.A, fontColor.R, fontColor.G, fontColor.B);
            //    var bg2 = System.Drawing.Color.FromArgb(bgColor.A, bgColor.R, bgColor.G, bgColor.B);

            //    using (var g = System.Drawing.Graphics.FromImage(bmp))
            //    {
            //        g.FillRectangle(new System.Drawing.SolidBrush(bg2), new Rectangle(0, 0, width, height));
            //        g.DrawString("" + ch, font, new System.Drawing.SolidBrush(fg2), 0, 0, StringFormat.GenericTypographic);
            //    }

            //    int bgint = WriteableBitmapExtensions.ConvertColor(Color.FromArgb(bgColor.A, bgColor.R, bgColor.G, bgColor.B));
            //    for (int y = 0; y < height; y++)
            //    {
            //        var line = new List<int>();
            //        for (int x = 0; x < width; x++)
            //        {
            //            var color = bmp.GetPixel(x, y);
            //            line.Add(WriteableBitmapExtensions.ConvertColor(Color.FromArgb(color.A, color.R, color.G, color.B)));
            //        }
            //        if (line.All(x => x == bgint)) continue; // all pixels filled with BG color
            //        int minx = line.FindIndex(x => x != bgint);
            //        int maxx = line.FindLastIndex(x => x != bgint);
            //        res.Add(y);
            //        res.Add(minx);
            //        res.Add(maxx - minx + 1);
            //        for (int i = minx; i <= maxx; i++) res.Add(line[i]);
            //    }
            //}

            //res.Add(-1); // end mark

            return new ClearTypeLetterGlyph
                {
                    Width = width,
                    Height = height,
                    Ch = ch,
                    //Instructions = res.ToArray(),
                    Items = res.ToArray(),
                };
        }

19 View Source File : D3DDevice.cs
License : GNU General Public License v3.0
Project Creator : anotak

public static int ARGB(float a, float r, float g, float b)
		{
			return Color.FromArgb((int)(a * 255f), (int)(r * 255f), (int)(g * 255f), (int)(b * 255f)).ToArgb();
		}

19 View Source File : D3DDevice.cs
License : GNU General Public License v3.0
Project Creator : anotak

public static int RGB(int r, int g, int b)
		{
			return Color.FromArgb(255, r, g, b).ToArgb();
		}

19 View Source File : PixelColor.cs
License : GNU General Public License v3.0
Project Creator : anotak

public int ToInt()
		{
			return Color.FromArgb(a, r, g, b).ToArgb();
		}

19 View Source File : PixelColor.cs
License : GNU General Public License v3.0
Project Creator : anotak

public Color ToColor()
		{
			return Color.FromArgb(a, r, g, b);
		}

19 View Source File : ColorExtensions.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : anoyetta

public static System.Drawing.Color ToLegacy(
            this System.Windows.Media.Color color)
        {
            return System.Drawing.Color.FromArgb(
                color.A,
                color.R,
                color.G,
                color.B);
        }

19 View Source File : ColorExtensions.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : anoyetta

public static System.Drawing.Color ChangeBrightness(
            this System.Drawing.Color color,
            double brightness)
        {
            int r = (int)(color.R * brightness);
            int g = (int)(color.G * brightness);
            int b = (int)(color.B * brightness);

            if (r < 0)
            {
                r = 0;
            }

            if (r > 255)
            {
                r = 255;
            }

            if (g < 0)
            {
                g = 0;
            }

            if (g > 255)
            {
                g = 255;
            }

            if (b < 0)
            {
                b = 0;
            }

            if (b > 255)
            {
                b = 255;
            }

            return System.Drawing.Color.FromArgb(
                color.A,
                (byte)r,
                (byte)g,
                (byte)b);
        }

19 View Source File : general.cs
License : GNU General Public License v3.0
Project Creator : antikmozib

public static void StyleDeletedItems(ref ListView lvListView, int PathColumnIndex)
        {
            foreach (ListViewItem item in lvListView.Items)
            {
                if (!File.Exists(ParseFileName(item, PathColumnIndex)))
                {
                    item.Font = new Font(item.Font, FontStyle.Strikeout);
                    item.Checked = false;
                    item.ForeColor = Color.FromArgb(255, 179, 179, 179);
                }
            }
        }

19 View Source File : ExcelDxfStyle.cs
License : Apache License 2.0
Project Creator : Appdynamics

private ExcelDxfColor GetColor(XmlHelperInstance helper, string path)
        {            
            ExcelDxfColor ret = new ExcelDxfColor(_styles);
            ret.Theme = helper.GetXmlNodeIntNull(path + "/@theme");
            ret.Index = helper.GetXmlNodeIntNull(path + "/@indexed");
            string rgb=helper.GetXmlNodeString(path + "/@rgb");
            if(rgb!="")
            {
                ret.Color = Color.FromArgb( int.Parse(rgb.Substring(0, 2), System.Globalization.NumberStyles.AllowHexSpecifier),
                                            int.Parse(rgb.Substring(2, 2), System.Globalization.NumberStyles.AllowHexSpecifier),
                                            int.Parse(rgb.Substring(4, 2), System.Globalization.NumberStyles.AllowHexSpecifier),
                                            int.Parse(rgb.Substring(6, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
            }
            ret.Auto = helper.GetXmlNodeBoolNullable(path + "/@auto");
            ret.Tint = helper.GetXmlNodeDoubleNull(path + "/@tint");
            return ret;
        }

19 View Source File : Sample14.cs
License : Apache License 2.0
Project Creator : Appdynamics

public static string RunSample14()
    {
      FileInfo newFile = Utils.GetFileInfo("sample14.xlsx");
      using (ExcelPackage package = new ExcelPackage(newFile))
      {
        // add a new worksheet to the empty workbook
        ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Conditional Formatting");

        // Create 4 columns of samples data
        for (int col = 1; col < 10; col++)
        {
          // Add the headers
          worksheet.Cells[1, col].Value = "Sample " + col;

          for (int row = 2; row < 21; row++)
          {
            // Add some items...
            worksheet.Cells[row, col].Value = row;
          }
        }

        // -------------------------------------------------------------------
        // TwoColorScale Conditional Formatting example
        // -------------------------------------------------------------------
        ExcelAddress cfAddress1 = new ExcelAddress("A2:A10");
        var cfRule1 = worksheet.ConditionalFormatting.AddTwoColorScale(cfAddress1);

        // Now, lets change some properties:
        cfRule1.LowValue.Type = eExcelConditionalFormattingValueObjectType.Num;
        cfRule1.LowValue.Value = 4;
        cfRule1.LowValue.Color = Color.FromArgb(0xFF, 0xFF, 0xEB, 0x84);
        cfRule1.HighValue.Type = eExcelConditionalFormattingValueObjectType.Formula;
        cfRule1.HighValue.Formula = "IF($G$1=\"A</x:&'cfRule>\",1,5)";
        cfRule1.StopIfTrue = true;
        cfRule1.Style.Font.Bold = true;

        // But others you can't (readonly)
        // cfRule1.Type = eExcelConditionalFormattingRuleType.ThreeColorScale;

        // -------------------------------------------------------------------
        // ThreeColorScale Conditional Formatting example
        // -------------------------------------------------------------------
        ExcelAddress cfAddress2 = new ExcelAddress(2, 2, 10, 2);  //="B2:B10"
        var cfRule2 = worksheet.ConditionalFormatting.AddThreeColorScale(cfAddress2);

        // Changing some properties again
        cfRule2.Priority = 1;
        cfRule2.MiddleValue.Type = eExcelConditionalFormattingValueObjectType.Percentile;
        cfRule2.MiddleValue.Value = 30;
        cfRule2.StopIfTrue = true;

        // You can access a rule by its Priority
        var cfRule2Priority = cfRule2.Priority;
        var cfRule2_1 = worksheet.ConditionalFormatting.RulesByPriority(cfRule2Priority);

        // And you can even change the rule's Address
        cfRule2_1.Address = new ExcelAddress("Z1:Z3");

        // -------------------------------------------------------------------
        // Adding another ThreeColorScale in a different way (observe that we are
        // pointing to the same range as the first rule we entered. Excel allows it to
        // happen and group the rules in one <conditionalFormatting> node)
        // -------------------------------------------------------------------
        var cfRule3 = worksheet.Cells[cfAddress1.Address].ConditionalFormatting.AddThreeColorScale();
        cfRule3.LowValue.Color = Color.LemonChiffon;
        
        // -------------------------------------------------------------------
        // Change the rules priorities to change their execution order
        // -------------------------------------------------------------------
        cfRule3.Priority = 1;
        cfRule1.Priority = 2;
        cfRule2.Priority = 3;

        // -------------------------------------------------------------------
        // Create an Above Average rule
        // -------------------------------------------------------------------
        var cfRule5 = worksheet.ConditionalFormatting.AddAboveAverage(
          new ExcelAddress("B11:B20"));
        cfRule5.Style.Font.Bold = true;
        cfRule5.Style.Font.Color.Color = Color.Red;
        cfRule5.Style.Font.Strike = true;

        // -------------------------------------------------------------------
        // Create an Above Or Equal Average rule
        // -------------------------------------------------------------------
        var cfRule6 = worksheet.ConditionalFormatting.AddAboveOrEqualAverage(
          new ExcelAddress("B11:B20"));

        // -------------------------------------------------------------------
        // Create a Below Average rule
        // -------------------------------------------------------------------
        var cfRule7 = worksheet.ConditionalFormatting.AddBelowAverage(
          new ExcelAddress("B11:B20"));

        // -------------------------------------------------------------------
        // Create a Below Or Equal Average rule
        // -------------------------------------------------------------------
        var cfRule8 = worksheet.ConditionalFormatting.AddBelowOrEqualAverage(
          new ExcelAddress("B11:B20"));

        // -------------------------------------------------------------------
        // Create a Above StdDev rule
        // -------------------------------------------------------------------
        var cfRule9 = worksheet.ConditionalFormatting.AddAboveStdDev(
          new ExcelAddress("B11:B20"));
          cfRule9.StdDev = 0;

        // -------------------------------------------------------------------
        // Create a Below StdDev rule
        // -------------------------------------------------------------------
        var cfRule10 = worksheet.ConditionalFormatting.AddBelowStdDev(
          new ExcelAddress("B11:B20"));

        cfRule10.StdDev = 2;

        // -------------------------------------------------------------------
        // Create a Bottom rule
        // -------------------------------------------------------------------
        var cfRule11 = worksheet.ConditionalFormatting.AddBottom(
          new ExcelAddress("B11:B20"));

        cfRule11.Rank = 4;

        // -------------------------------------------------------------------
        // Create a Bottom Percent rule
        // -------------------------------------------------------------------
        var cfRule12 = worksheet.ConditionalFormatting.AddBottomPercent(
          new ExcelAddress("B11:B20"));

        cfRule12.Rank = 15;

        // -------------------------------------------------------------------
        // Create a Top rule
        // -------------------------------------------------------------------
        var cfRule13 = worksheet.ConditionalFormatting.AddTop(
          new ExcelAddress("B11:B20"));

        // -------------------------------------------------------------------
        // Create a Top Percent rule
        // -------------------------------------------------------------------
        var cfRule14 = worksheet.ConditionalFormatting.AddTopPercent(
          new ExcelAddress("B11:B20"));
        
        cfRule14.Style.Border.Left.Style = ExcelBorderStyle.Thin;
        cfRule14.Style.Border.Left.Color.Theme = 3;
        cfRule14.Style.Border.Bottom.Style = ExcelBorderStyle.DashDot;
        cfRule14.Style.Border.Bottom.Color.Index=8;
        cfRule14.Style.Border.Right.Style = ExcelBorderStyle.Thin;
        cfRule14.Style.Border.Right.Color.Color=Color.Blue;
        cfRule14.Style.Border.Top.Style = ExcelBorderStyle.Hair;
        cfRule14.Style.Border.Top.Color.Auto=true;

        // -------------------------------------------------------------------
        // Create a Last 7 Days rule
        // -------------------------------------------------------------------
        ExcelAddress timePeriodAddress = new ExcelAddress("D21:G34 C11:C20");
        var cfRule15 = worksheet.ConditionalFormatting.AddLast7Days(
          timePeriodAddress);

        cfRule15.Style.Fill.PatternType = ExcelFillStyle.LightTrellis;
        cfRule15.Style.Fill.PatternColor.Color = Color.BurlyWood;
        cfRule15.Style.Fill.BackgroundColor.Color = Color.LightCyan;

        // -------------------------------------------------------------------
        // Create a Last Month rule
        // -------------------------------------------------------------------
        var cfRule16 = worksheet.ConditionalFormatting.AddLastMonth(
          timePeriodAddress);

        cfRule16.Style.NumberFormat.Format = "YYYY";
        // -------------------------------------------------------------------
        // Create a Last Week rule
        // -------------------------------------------------------------------
        var cfRule17 = worksheet.ConditionalFormatting.AddLastWeek(
          timePeriodAddress);
        cfRule17.Style.NumberFormat.Format = "YYYY";

        // -------------------------------------------------------------------
        // Create a Next Month rule
        // -------------------------------------------------------------------
        var cfRule18 = worksheet.ConditionalFormatting.AddNextMonth(
          timePeriodAddress);

        // -------------------------------------------------------------------
        // Create a Next Week rule
        // -------------------------------------------------------------------
        var cfRule19 = worksheet.ConditionalFormatting.AddNextWeek(
          timePeriodAddress);

        // -------------------------------------------------------------------
        // Create a This Month rule
        // -------------------------------------------------------------------
        var cfRule20 = worksheet.ConditionalFormatting.AddThisMonth(
          timePeriodAddress);

        // -------------------------------------------------------------------
        // Create a This Week rule
        // -------------------------------------------------------------------
        var cfRule21 = worksheet.ConditionalFormatting.AddThisWeek(
          timePeriodAddress);

        // -------------------------------------------------------------------
        // Create a Today rule
        // -------------------------------------------------------------------
        var cfRule22 = worksheet.ConditionalFormatting.AddToday(
          timePeriodAddress);

        // -------------------------------------------------------------------
        // Create a Tomorrow rule
        // -------------------------------------------------------------------
        var cfRule23 = worksheet.ConditionalFormatting.AddTomorrow(
          timePeriodAddress);

        // -------------------------------------------------------------------
        // Create a Yesterday rule
        // -------------------------------------------------------------------
        var cfRule24 = worksheet.ConditionalFormatting.AddYesterday(
          timePeriodAddress);

        // -------------------------------------------------------------------
        // Create a BeginsWith rule
        // -------------------------------------------------------------------
        ExcelAddress cellIsAddress = new ExcelAddress("E11:E20");
        var cfRule25 = worksheet.ConditionalFormatting.AddBeginsWith(
          cellIsAddress);

        cfRule25.Text = "SearchMe";

        // -------------------------------------------------------------------
        // Create a Between rule
        // -------------------------------------------------------------------
        var cfRule26 = worksheet.ConditionalFormatting.AddBetween(
          cellIsAddress);

        cfRule26.Formula = "IF(E11>5,10,20)";
        cfRule26.Formula2 = "IF(E11>5,30,50)";

        // -------------------------------------------------------------------
        // Create a ContainsBlanks rule
        // -------------------------------------------------------------------
        var cfRule27 = worksheet.ConditionalFormatting.AddContainsBlanks(
          cellIsAddress);

        // -------------------------------------------------------------------
        // Create a ContainsErrors rule
        // -------------------------------------------------------------------
        var cfRule28 = worksheet.ConditionalFormatting.AddContainsErrors(
          cellIsAddress);

        // -------------------------------------------------------------------
        // Create a ContainsText rule
        // -------------------------------------------------------------------
        var cfRule29 = worksheet.ConditionalFormatting.AddContainsText(
          cellIsAddress);

        cfRule29.Text = "Me";

        // -------------------------------------------------------------------
        // Create a DuplicateValues rule
        // -------------------------------------------------------------------
        var cfRule30 = worksheet.ConditionalFormatting.AddDuplicateValues(
          cellIsAddress);

        // -------------------------------------------------------------------
        // Create an EndsWith rule
        // -------------------------------------------------------------------
        var cfRule31 = worksheet.ConditionalFormatting.AddEndsWith(
          cellIsAddress);

        cfRule31.Text = "EndText";

        // -------------------------------------------------------------------
        // Create an Equal rule
        // -------------------------------------------------------------------
        var cfRule32 = worksheet.ConditionalFormatting.AddEqual(
          cellIsAddress);

        cfRule32.Formula = "6";

        // -------------------------------------------------------------------
        // Create an Expression rule
        // -------------------------------------------------------------------
        var cfRule33 = worksheet.ConditionalFormatting.AddExpression(
          cellIsAddress);

        cfRule33.Formula = "E11=E12";

        // -------------------------------------------------------------------
        // Create a GreaterThan rule
        // -------------------------------------------------------------------
        var cfRule34 = worksheet.ConditionalFormatting.AddGreaterThan(
          cellIsAddress);

        cfRule34.Formula = "SE(E11<10,10,65)";

        // -------------------------------------------------------------------
        // Create a GreaterThanOrEqual rule
        // -------------------------------------------------------------------
        var cfRule35 = worksheet.ConditionalFormatting.AddGreaterThanOrEqual(
          cellIsAddress);

        cfRule35.Formula = "35";

        // -------------------------------------------------------------------
        // Create a LessThan rule
        // -------------------------------------------------------------------
        var cfRule36 = worksheet.ConditionalFormatting.AddLessThan(
          cellIsAddress);

        cfRule36.Formula = "36";

        // -------------------------------------------------------------------
        // Create a LessThanOrEqual rule
        // -------------------------------------------------------------------
        var cfRule37 = worksheet.ConditionalFormatting.AddLessThanOrEqual(
          cellIsAddress);

        cfRule37.Formula = "37";

        // -------------------------------------------------------------------
        // Create a NotBetween rule
        // -------------------------------------------------------------------
        var cfRule38 = worksheet.ConditionalFormatting.AddNotBetween(
          cellIsAddress);

        cfRule38.Formula = "333";
        cfRule38.Formula2 = "999";

        // -------------------------------------------------------------------
        // Create a NotContainsBlanks rule
        // -------------------------------------------------------------------
        var cfRule39 = worksheet.ConditionalFormatting.AddNotContainsBlanks(
          cellIsAddress);

        // -------------------------------------------------------------------
        // Create a NotContainsErrors rule
        // -------------------------------------------------------------------
        var cfRule40 = worksheet.ConditionalFormatting.AddNotContainsErrors(
          cellIsAddress);

        // -------------------------------------------------------------------
        // Create a NotContainsText rule
        // -------------------------------------------------------------------
        var cfRule41 = worksheet.ConditionalFormatting.AddNotContainsText(
          cellIsAddress);

        cfRule41.Text = "NotMe";

        // -------------------------------------------------------------------
        // Create an NotEqual rule
        // -------------------------------------------------------------------
        var cfRule42 = worksheet.ConditionalFormatting.AddNotEqual(
          cellIsAddress);

        cfRule42.Formula = "14";

        ExcelAddress cfAddress43 = new ExcelAddress("G2:G10");
        var cfRule43 = worksheet.ConditionalFormatting.AddThreeIconSet(cfAddress43, eExcelconditionalFormatting3IconsSetType.TrafficLights1);

        ExcelAddress cfAddress44 = new ExcelAddress("H2:H10");
        var cfRule44 = worksheet.ConditionalFormatting.AddDatabar(cfAddress44, Color.DarkBlue);
        
          // -----------------------------------------------------------
        // Removing Conditional Formatting rules
        // -----------------------------------------------------------
        // Remove one Rule by its object
        //worksheet.ConditionalFormatting.Remove(cfRule1);

        // Remove one Rule by index
        //worksheet.ConditionalFormatting.RemoveAt(1);

        // Remove one Rule by its Priority
        //worksheet.ConditionalFormatting.RemoveByPriority(2);

        // Remove all the Rules
        //worksheet.ConditionalFormatting.RemoveAll();

        // set some doreplacedent properties
        package.Workbook.Properties.replacedle = "Conditional Formatting";
        package.Workbook.Properties.Author = "Eyal Seagull";
        package.Workbook.Properties.Comments = "This sample demonstrates how to add Conditional Formatting to an Excel 2007 worksheet using EPPlus";

        // set some custom property values
        package.Workbook.Properties.SetCustomPropertyValue("Checked by", "Eyal Seagull");
        package.Workbook.Properties.SetCustomPropertyValue("replacedemblyName", "EPPlus");

        // save our new workbook and we are done!
        package.Save();
      }

      return newFile.FullName;
    }

19 View Source File : Sample6.cs
License : Apache License 2.0
Project Creator : Appdynamics

private static Bitmap GetIcon(string FileName)
        {
            try
            {
                SHFILEINFO shinfo = new SHFILEINFO();                

                var ret = SHGetFileInfo(FileName,
                                          0,
                                          ref shinfo,
                                          (uint)Marshal.SizeOf(shinfo),
                                          SHGFI_ICON | SHGFI_SMALLICON);

                if (shinfo.hIcon == IntPtr.Zero) return null;

                Bitmap bmp = Icon.FromHandle(shinfo.hIcon).ToBitmap();
                DestroyIcon(shinfo.hIcon);

                //Fix transparant color 
                Color InvalidColor = Color.FromArgb(0, 0, 0, 0);
                for (int w = 0; w < bmp.PhysicalDimension.Width; w++)
                {
                    for (int h = 0; h < bmp.PhysicalDimension.Height; h++)
                    {
                        if (bmp.GetPixel(w, h) == InvalidColor)
                        {
                            bmp.SetPixel(w, h, Color.Transparent);
                        }
                    }
                }

                return bmp;
            }
            catch
            {
                return null;
            }
        }

protected void UpdateTextBox(TextBox textBox)
        {
            if (Emitter == null)
            {
                return;
            }

            if (textBox.Tag == null)
            {
                return;
            }

            UpdateTextBoxText(textBox);

            var property = textBox.Tag.ToString();
            textBox.Enabled = Emitter.IsEditable;

            if (Emitter.IsEditable && Emitter.GetType().GetProperty(property + "FontWeight") != null)
            {
                var fontWeight =
                    (FontWeight) Emitter.GetType().GetProperty(property + "FontWeight").GetValue(Emitter);
                textBox.Font = new Font(textBox.Font,
                    fontWeight == FontWeights.Bold ? FontStyle.Bold : FontStyle.Regular);

                var solidBrush =
                    (SolidColorBrush) Emitter.GetType().GetProperty(property + "Brush").GetValue(Emitter);
                var foreColor = Color.FromArgb(
                    solidBrush.Color.A,
                    solidBrush.Color.R,
                    solidBrush.Color.G,
                    solidBrush.Color.B);
                textBox.ForeColor = foreColor;
            }
            else
            {
                // this value is never editable, that's why it doesn't have a "FontWeight"
                textBox.Enabled = false;
            }
        }

protected void UpdateTextBox(TextBox textBox)
        {
            if (textBox.Tag == null)
            {
                return;
            }

            UpdateTextBoxText(textBox);

            var property = textBox.Tag.ToString();
            textBox.Enabled = Conversion.IsEditable;

            if (Conversion.IsEditable && Conversion.GetType().GetProperty(property + "FontWeight") != null)
            {
                var fontWeight =
                    (FontWeight) Conversion.GetType().GetProperty(property + "FontWeight").GetValue(Conversion);
                textBox.Font = new Font(textBox.Font,
                    fontWeight == FontWeights.Bold ? FontStyle.Bold : FontStyle.Regular);

                var solidBrush =
                    (SolidColorBrush) Conversion.GetType().GetProperty(property + "Brush").GetValue(Conversion);
                var foreColor = Color.FromArgb(
                    solidBrush.Color.A,
                    solidBrush.Color.R,
                    solidBrush.Color.G,
                    solidBrush.Color.B);
                textBox.ForeColor = foreColor;
            }
            else
            {
                // this value is never editable, that's why it doesn't have a "FontWeight"
                textBox.Enabled = false;
            }
        }

private void UpdateTextBox(TextBox textBox, bool? editableOverride = null)
        {
            bool editable = editableOverride ?? State.IsEditable;

            var stateProperty = textBox.Tag.ToString();
            textBox.Text = State.GetType().GetProperty(stateProperty).GetValue(State) as string;
            textBox.Enabled = editable;

            if (editable)
            {
                var fontWeight = (FontWeight) State.GetType().GetProperty(stateProperty + "FontWeight").GetValue(State);
                textBox.Font = new Font(textBox.Font, fontWeight == FontWeights.Bold? FontStyle.Bold: FontStyle.Regular);

                var solidBrush = (SolidColorBrush) State.GetType().GetProperty(stateProperty + "Brush").GetValue(State);
                var foreColor = System.Drawing.Color.FromArgb(
                    solidBrush.Color.A, 
                    solidBrush.Color.R, 
                    solidBrush.Color.G,
                    solidBrush.Color.B);
                textBox.ForeColor = foreColor;
            }
        }

19 View Source File : Animation.cs
License : MIT License
Project Creator : arcusmaximus

protected Color Interpolate(Color from, Color to, float t)
        {
            return Color.FromArgb(
                Interpolate(from.A, to.A, t),
                Interpolate(from.R, to.R, t),
                Interpolate(from.G, to.G, t),
                Interpolate(from.B, to.B, t)
            );
        }

19 View Source File : AssChromaTagHandler.cs
License : MIT License
Project Creator : arcusmaximus

public override void Handle(replacedTagContext context, string arg)
        {
            if (!TryParseArgs(arg, out List<Color> colors, out int alpha, out int maxOffsetX, out int maxOffsetY, out int chromaInMs, out int chromeOutMs))
                return;

            context.PostProcessors.Add(
                () =>
                {
                    replacedLine originalLine = context.Line;
                    PointF center = originalLine.Position ?? context.Doreplacedent.GetDefaultPosition(originalLine.AnchorPoint);
                    List<replacedLine> chromaLines = new List<replacedLine>();

                    if (colors.Count == 0)
                    {
                        Color baseColor = context.Line.Sections.Count > 0 ? context.Line.Sections[0].ForeColor : Color.White;
                        colors.Add(Color.FromArgb((int)(baseColor.R * alpha / 255.0f), 255, 0, 0));
                        colors.Add(Color.FromArgb((int)(baseColor.G * alpha / 255.0f), 0, 255, 0));
                        colors.Add(Color.FromArgb((int)(baseColor.B * alpha / 255.0f), 0, 0, 255));
                    }

                    if (chromaInMs > 0)
                    {
                        chromaLines.AddRange(CreateChromaLines(originalLine, colors, center, maxOffsetX, maxOffsetY, chromaInMs, true));
                        originalLine.Start = TimeUtil.RoundTimeToFrameCenter(originalLine.Start.AddMilliseconds(chromaInMs));
                    }

                    if (chromeOutMs > 0)
                    {
                        chromaLines.AddRange(CreateChromaLines(originalLine, colors, center, maxOffsetX, maxOffsetY, chromeOutMs, false));
                        originalLine.End = TimeUtil.RoundTimeToFrameCenter(originalLine.End.AddMilliseconds(-chromeOutMs));
                    }

                    return chromaLines;
                }
            );
        }

19 View Source File : AssTagHandlerBase.cs
License : MIT License
Project Creator : arcusmaximus

protected static Color ParseColor(string arg, int alpha)
        {
            int bgr = ParseHex(arg);
            byte r = (byte)bgr;
            byte g = (byte)(bgr >> 8);
            byte b = (byte)(bgr >> 16);
            return Color.FromArgb(alpha, r, g, b);
        }

See More Examples