title: How to draw transparent image in c#
body: <p>I made a ListBox.</p>
  
  <p>There are image and Text in ListBox Like picture.</p>
  
  <p><a href="https://i.stack.imgur.com/vhxmZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vhxmZ.png" alt="enter image description here"></a></p>
  
  <p>And i want to draw transparent Image on listbox When mousemove.</p>
  
  <pre><code>private void ListBox_DrawItem(object sender, DrawItemEventArgs e)
  {
      int iWidth = image.Width;
      int iHeight = image.Height;
  
      ImageAttributes attr = new ImageAttributes();
  
      ColorMatrix matrix = new ColorMatrix();
      matrix.Matrix33 = 0.8f;
      attr.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
  
      e.Graphics.DrawImage(image, new Rectangle(0, 0 iWidth, iHeight), 0, 0, iWidth, iHeight, GraphicsUnit.Pixel, attr);
  }
  </code></pre>
  
  <p>This is my code.</p>
  
  <p>But I have a problem.</p>
  
  <p>Although I input the same value of transparency, Transparency of each image is different..</p>
  
  <p>How can I solve it ??</p>
  
  <p>++ Add Code</p>
  
  <p>I use Scrollbar.</p>
  
  <pre><code>int LocationY = ListBox.PreferredHeight / ListBox.Items.Count * (Index/*ListBox index*/ - ListBox.TopIndex);
  if ((LocationY + image.Height) &gt; Listbox.Height)
         LocationY = ListBox.Height - image.Height;
  
  e.Graphics.DrawImage(image, new Rectangle(0, LocationY, iWidth, iHeight), 0, 0, iWidth, iHeight, GraphicsUnit.Pixel, attr); 
  </code></pre>