Transparent color : Color « 2D Graphics « C# / C Sharp






Transparent color

Transparent color
   
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form
{

  public Form1() {
        InitializeComponent();
  }
  private void Form1_Paint(object sender, PaintEventArgs e)
  {
    Bitmap bitmap = new Bitmap("winter.jpg");
    TextureBrush brush = new TextureBrush(bitmap);
    e.Graphics.FillRectangle(brush, ClientRectangle);
        bitmap.Dispose();

    Color color = Color.Yellow;
    int penWidth = 80;
    Pen opaquePen = new Pen(color, penWidth);
    e.Graphics.DrawLine(opaquePen, 0, 50, 200, 20);
        opaquePen.Dispose();

    Color semiTransparentColor = Color.FromArgb(128, color.R, color.G, color.B);
    Pen semiTransparentPen = new Pen(semiTransparentColor, penWidth);
    e.Graphics.DrawLine(semiTransparentPen, 0, 200, 200, 140);
        semiTransparentPen.Dispose();

    Color veryTransparentColor = Color.FromArgb(77, color.R, color.G, color.B);
    Pen veryTransparentPen = new Pen(veryTransparentColor, penWidth);
    e.Graphics.DrawLine(veryTransparentPen, 0, 350, 200, 260);
        veryTransparentPen.Dispose();
  
    Brush transparentBrush = new SolidBrush(semiTransparentColor);
    e.Graphics.DrawString("www.java2s.com", new Font("Verdana", 36, FontStyle.Bold),
      transparentBrush, 80, 150);
  }

  private void InitializeComponent()
  {
    this.SuspendLayout();
    // 
    // Form1
    // 
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(292, 266);
    this.Name = "Form1";
    this.Text = "Alpha Blending";
    this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
    this.ResumeLayout(false);

  }


  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }

}



           
         
    
    
  








Related examples in the same category

1.List all known color in a systemList all known color in a system
2.Draw each of 100 cells with randomly chosen colorsDraw each of 100 cells with randomly chosen colors
3.Filled with the semi transparent and transparent colorFilled with the semi transparent and transparent color
4.All the colors that are supported in C# according
5.Color ChangerColor Changer
6.Known ColorsKnown Colors
7.Five yellow squares with different alpha values(Transparensy)
8.Create two color instances with different alpha components
9.Color.Chocolate
10.Use Color.FromArgb to create Color
11.Get all known color
12.Color representation in r,g,b with values [0.0 - 1.0].
13.Color representation in h,s,v with h = [0 - 360], s,v = [0.0 - 1.0].
14.Return a randomly-generated color
15.Color to RGB value
16.Get color outof String
17.Parse Color
18.Color To Rgb
19.Rgb To Color
20.Returns an HTML #XXXXXX format for a color.
21.Convert color name to Color object
22.Hex Color Util
23.Helper method to get a color based on it's string value
24.Converts a color string to a hex value string
25.Color to Hue,Lightness,Saturation value
26.Get Color From String
27.Convert String value To Color
28.Color to String
29.Masks an image and returns a two color bitmap.
30.Convert Hex To Color
31.Create Color From HLS value
32.Parse Color with Color.FromArgb
33.Create Color Object from RGB value
34.Get Rainbow Colors
35.Convert RGB to HSL
36.HSL to RGB conversion.
37.Hsv To Rgb
38.Rgb Linear Interpolate
39.Get Luminance
40.To Grey scale
41.Heat Map background colour calculations