Blend Alpha : Blend « 2D Graphics « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » 2D Graphics » BlendScreenshots 
Blend Alpha
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(4020100100 );
    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 Disposebool disposing )
        {
            ifdisposing )
            {
                if (components != null
                {
                    components.Dispose();
                }
        if I != null )
          I.Dispose();
        if Ia != null )
          Ia.Dispose();
      }

            base.Disposedisposing );
        }

        #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(32128);
      this.AlphaScroll.Maximum = 255;
      this.AlphaScroll.Name = "AlphaScroll";
      this.AlphaScroll.Size = new System.Drawing.Size(16016);
      this.AlphaScroll.TabIndex = 1;
      this.AlphaScroll.Scroll += new System.Windows.Forms.ScrollEventHandler(this.AlphaScroll_Scroll);
      // 
      // GammaScroll
      // 
      this.GammaScroll.Location = new System.Drawing.Point(328);
      this.GammaScroll.Name = "GammaScroll";
      this.GammaScroll.Size = new System.Drawing.Size(16016);
      this.GammaScroll.TabIndex = 2;
      this.GammaScroll.Scroll += new System.Windows.Forms.ScrollEventHandler(this.GammaScroll_Scroll);
      // 
      // Blend
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(513);
      this.ClientSize = new System.Drawing.Size(292273);
      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 AlphaBlendGraphics G )
    {
      //AlphaFactor is variable depeneding upon scroll bars
      Pen P = new PenColor.FromArgb (AlphaFactor, 2000100 )20);
      Bitmap bmp = new Bitmap120120 );
      Graphics G2 = Graphics.FromImage(bmp);
      Brush B = new SolidBrush(Color.FromArgbAlphaFactor, 5020050 ));

      try
      {
        // Set the brightness while rendering image
        Ia.SetGammaGammaFactor );
        G.DrawImage(I, R, 00, ImWidth, ImHeight, GraphicsUnit.Pixel, Ia);
        //Draw transparent line on top of image
        G.DrawLine(P, 10100200100 );

        // Draw inside the image contained in memory
        G2.FillEllipseB, 007575 );
        G.DrawImageI, new Rectangle(140140120120 ) );
        G.CompositingQuality = CompositingQuality.GammaCorrected;
        G.CompositingMode = CompositingMode.SourceOver;
        G.DrawImagebmp, new Rectangle150150150150 ) );
      }
      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)
Related examples in the same category
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.