title: Change alpha coefficient using Lockbits
body: <p>I have written a function which changes the alpha coefficient of an image. I use setpixel and getpixel,which is very slow. I found out that Lockbits method is faster.How can I do it with Lockbits?
  Here is my current code:</p>
  
  <pre><code> using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Drawing.Imaging;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  
  namespace WindowsFormsApplication2
  {
      public partial class Form1 : Form
      {
          private static Image Tran(Image s,int alpha)
          {
              int x = 0, y = 0;
              Bitmap tImage = new Bitmap(s);
              for (x = 0; x &lt; tImage.Width; x++)
              {
                  for (y = 0; y &lt; tImage.Height; y++)
                  {
  
                      tImage.SetPixel(x, y, Color.FromArgb(alpha, tImage.GetPixel(x, y).R, tImage.GetPixel(x, y).G, tImage.GetPixel(x, y).B));
                  }
              }
              return tImage;
  
          }
          public Form1()
          {
              InitializeComponent();
              trackBar1.TickStyle = TickStyle.Both;
              trackBar1.Orientation = Orientation.Vertical;
              trackBar1.Minimum = 0;
              trackBar1.Maximum = 255;
              trackBar1.Height = 101;
              trackBar1.Value = 255;
              pictureBox1.Image = Image.FromFile("C:\\Users\\rati\\Desktop\\water.jpg");
              pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
          }
          private void trackBar1_Scroll(object sender, EventArgs e)
          {
              pictureBox1.Image = ChangeAlpha(pictureBox1.Image, trackBar1.Value);
  
              textBox1.Text = trackBar1.Value.ToString();
  
          }
  
  
      }
  }
  </code></pre>