Use Brushes.Aquamarine to draw a Ellipse


   

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;

public class Form1 : System.Windows.Forms.Form{
  private System.ComponentModel.Container components = null;

  public Form1(){
    InitializeComponent();
        SetStyle(ControlStyles.Opaque, true);
  }
  protected override void Dispose( bool disposing ){
    if( disposing ){
      if (components != null) 
      {
        components.Dispose();
      }
    }
    base.Dispose( disposing );
  }
    protected override void OnPaint(PaintEventArgs e) {
         Graphics g = e.Graphics;
         g.FillRectangle(Brushes.White, ClientRectangle);

         g.FillEllipse(Brushes.Aquamarine, new Rectangle(60, 20, 50, 30));
    }
  private void InitializeComponent(){
    this.components = new System.ComponentModel.Container();
    this.Size = new System.Drawing.Size(300,300);
    this.Text = "Form1";
  }
  static void Main() {
    Application.Run(new Form1());
  }
}



           
          


Use Brushes.BlueViolet ro draw a Polygon


   

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;

public class Form1 : System.Windows.Forms.Form{
  private System.ComponentModel.Container components = null;

  public Form1(){
    InitializeComponent();
        SetStyle(ControlStyles.Opaque, true);
  }
  protected override void Dispose( bool disposing ){
    if( disposing ){
      if (components != null) 
      {
        components.Dispose();
      }
    }
    base.Dispose( disposing );
  }
    protected override void OnPaint(PaintEventArgs e) {
         Graphics g = e.Graphics;
         g.FillRectangle(Brushes.White, ClientRectangle);



         g.FillPolygon(Brushes.BlueViolet, new Point[] {
                                                          new Point(110, 10),
                                                          new Point(150, 10),
                                                          new Point(160, 40),
                                                          new Point(120, 20),
                                                          new Point(120, 60),
         });
    }
  private void InitializeComponent(){
    this.components = new System.ComponentModel.Container();
    this.Size = new System.Drawing.Size(300,300);
    this.Text = "Form1";
  }
  static void Main() {
    Application.Run(new Form1());
  }
}



           
          


Solid brush demo


   

  using System;
  using System.Drawing;
  using System.Collections;
  using System.ComponentModel;
  using System.Windows.Forms;
  using System.Data;

  public class MainForm : System.Windows.Forms.Form
  {
    private System.ComponentModel.Container components;

    public MainForm()
    {
      InitializeComponent();
      BackColor = Color.LemonChiffon;  
      Text = "www.kutayzorlu.com/java2s/com";    
      Size = new Size(200, 200);    
      CenterToScreen();        
    }

    protected override void Dispose( bool disposing )
    {
      if( disposing )
      {
        if (components != null) 
        {
          components.Dispose();
        }
      }
      base.Dispose( disposing );
    }

    private void InitializeComponent()
    {
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(292, 273);
      this.Text = "Form1";
      this.Resize += new System.EventHandler(this.MainForm_Resize);
      this.Paint += new System.Windows.Forms.PaintEventHandler(this.MainForm_Paint);

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

    private void MainForm_Resize(object sender, System.EventArgs e)
    {
      Invalidate();
    }

    private void MainForm_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
      Graphics g = e.Graphics;
      g.DrawString("www.kutayzorlu.com/java2s/com", 
        new Font("Times New Roman", 20), 
        new SolidBrush(Color.Black), 
        this.DisplayRectangle);
    }
  }



           
          


Brushes.Black

   
 

using System;
using System.Drawing;
using System.Windows.Forms;
   
class HelloWorld: Form
{
     public static void Main()
     {
          Application.Run(new HelloWorld());
     }
     public HelloWorld()
     {
          Text = "Hello World";
          BackColor = Color.White;
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          Graphics graphics = pea.Graphics;
   
          graphics.DrawString("Hello, Windows Forms!", Font, 
                          Brushes.Black, 0, 0);
     }
}

    


Blend Alpha



   

/*
GDI+ Programming in C# and VB .NET
by Nick Symmonds

Publisher: Apress
ISBN: 159059035X
*/
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Blend_c
{ 
    public class Blend : System.Windows.Forms.Form
    {
    private System.Windows.Forms.HScrollBar AlphaScroll;
    private System.Windows.Forms.HScrollBar GammaScroll;
    /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

    private int AlphaFactor = 255;
    private float GammaFactor = 1.0f;
    private Rectangle R = new Rectangle(40, 20, 100, 100 );
    private Image I = Image.FromFile("Colorbars.jpg");
    private int ImWidth;
    private int ImHeight;
    private ImageAttributes Ia = new ImageAttributes();



        public Blend()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

      AlphaScroll.Minimum = 20;
      AlphaScroll.Maximum = 245;
      AlphaScroll.SmallChange = 5;
      AlphaScroll.LargeChange = 5;
      AlphaScroll.Left = R.Left;
      AlphaScroll.Width = R.Width;
      AlphaScroll.Top = R.Bottom;

      GammaScroll.Minimum=1;
      GammaScroll.Maximum = 50;
      GammaScroll.SmallChange=1;
      GammaScroll.LargeChange=5;
      GammaScroll.Left = R.Left;
      GammaScroll.Top = R.Top - GammaScroll.Height;
      GammaScroll.Width = R.Width;

      ImWidth = I.Width;
      ImHeight = I.Height;

      AlphaScroll.Value = (AlphaScroll.Maximum-AlphaScroll.Minimum )/2;
      GammaScroll.Value = (GammaScroll.Maximum-GammaScroll.Minimum )/2;
      AlphaFactor = AlphaScroll.Value;
      GammaFactor = (float)GammaScroll.Value / 10;

    }

        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
        if ( I != null )
          I.Dispose();
        if ( Ia != null )
          Ia.Dispose();
      }

            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
      this.AlphaScroll = new System.Windows.Forms.HScrollBar();
      this.GammaScroll = new System.Windows.Forms.HScrollBar();
      this.SuspendLayout();
      // 
      // AlphaScroll
      // 
      this.AlphaScroll.Location = new System.Drawing.Point(32, 128);
      this.AlphaScroll.Maximum = 255;
      this.AlphaScroll.Name = "AlphaScroll";
      this.AlphaScroll.Size = new System.Drawing.Size(160, 16);
      this.AlphaScroll.TabIndex = 1;
      this.AlphaScroll.Scroll += new System.Windows.Forms.ScrollEventHandler(this.AlphaScroll_Scroll);
      // 
      // GammaScroll
      // 
      this.GammaScroll.Location = new System.Drawing.Point(32, 8);
      this.GammaScroll.Name = "GammaScroll";
      this.GammaScroll.Size = new System.Drawing.Size(160, 16);
      this.GammaScroll.TabIndex = 2;
      this.GammaScroll.Scroll += new System.Windows.Forms.ScrollEventHandler(this.GammaScroll_Scroll);
      // 
      // Blend
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(292, 273);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                  this.GammaScroll,
                                                                  this.AlphaScroll});
      this.Name = "Blend";
      this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
      this.Text = "Blend";
      this.Load += new System.EventHandler(this.Blend_Load);
      this.ResumeLayout(false);

    }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new Blend());
        }

    private void Blend_Load(object sender, System.EventArgs e)
    {
    }
    protected override void OnPaint(PaintEventArgs e)
    {
      AlphaBlend(e.Graphics);
      base.OnPaint(e);
    }

    private void AlphaBlend( Graphics G )
    {
      //AlphaFactor is variable depeneding upon scroll bars
      Pen P = new Pen( Color.FromArgb (AlphaFactor, 200, 0, 100 ), 20);
      Bitmap bmp = new Bitmap( 120, 120 );
      Graphics G2 = Graphics.FromImage(bmp);
      Brush B = new SolidBrush(Color.FromArgb( AlphaFactor, 50, 200, 50 ));

      try
      {
        // Set the brightness while rendering image
        Ia.SetGamma( GammaFactor );
        G.DrawImage(I, R, 0, 0, ImWidth, ImHeight, GraphicsUnit.Pixel, Ia);
        //Draw transparent line on top of image
        G.DrawLine(P, 10, 100, 200, 100 );

        // Draw inside the image contained in memory
        G2.FillEllipse( B, 0, 0, 75, 75 );
        G.DrawImage( I, new Rectangle(140, 140, 120, 120 ) );
        G.CompositingQuality = CompositingQuality.GammaCorrected;
        G.CompositingMode = CompositingMode.SourceOver;
        G.DrawImage( bmp, new Rectangle( 150, 150, 150, 150 ) );
      }
      finally
      {
        if (bmp != null )
          bmp.Dispose();
        if ( G2 != null )
          G2.Dispose();
        if ( B != null )
          B.Dispose();
        if ( P != null )
          P.Dispose();
      }
    }

    private void AlphaScroll_Scroll(object sender, 
                                    System.Windows.Forms.ScrollEventArgs e)
    {
      AlphaFactor = AlphaScroll.Value;
      this.Refresh();
    }

    private void GammaScroll_Scroll(object sender, 
                                    System.Windows.Forms.ScrollEventArgs e)
    {
      GammaFactor = (float)GammaScroll.Value / 10;
      this.Refresh();
    }

    }
}



           
          


Blend-c.zip( 5 k)

Scale Bitmap By Percent

   
 

//Octavalent Extension Methods
//http://sdfasdf.codeplex.com/
//Library of extension methods for .Net create by Octavalent (www.octavalent.nl)


#region

using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

#endregion

namespace System.Drawing.OctavalentExtensions
{
    public static class BitmapExtensions
    {
        public static Bitmap ScaleByPercent(this Bitmap imgPhoto, int Percent)
        {
            float nPercent = ((float) Percent/100);

            int sourceWidth = imgPhoto.Width;
            int sourceHeight = imgPhoto.Height;
            var destWidth = (int) (sourceWidth*nPercent);
            var destHeight = (int) (sourceHeight*nPercent);

            var bmPhoto = new Bitmap(destWidth, destHeight,
                                     PixelFormat.Format24bppRgb);
            bmPhoto.SetResolution(imgPhoto.HorizontalResolution,
                                  imgPhoto.VerticalResolution);

            Graphics grPhoto = Graphics.FromImage(bmPhoto);
            grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;

            grPhoto.DrawImage(imgPhoto,
                              new Rectangle(0, 0, destWidth, destHeight),
                              new Rectangle(0, 0, sourceWidth, sourceHeight),
                              GraphicsUnit.Pixel);

            grPhoto.Dispose();
            return bmPhoto;
        }
    }
}

   
     


PixelFormat.DontCare

   
  

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 {

    protected override void OnPaint(PaintEventArgs e) {
    Graphics g = e.Graphics;
    Bitmap bmp = new Bitmap("rama.jpg");
    g.FillRectangle(Brushes.White, this.ClientRectangle);

    Rectangle r = new Rectangle(120, 120, 400, 400);
    Bitmap bmp2 = bmp.Clone(r, System.Drawing.Imaging.PixelFormat.DontCare);
    g.DrawImage(bmp, new Rectangle(0, 0, 200, 200));
    g.DrawImage(bmp2, new Rectangle(210, 0, 200, 200));
    bmp2.Dispose();
    }
    public static void Main() {
        Application.Run(new Form1());
    }
}