Takes and image and converts it to a disabled-looking image. - CSharp System.Drawing

CSharp examples for System.Drawing:Image Effect

Description

Takes and image and converts it to a disabled-looking image.

Demo Code


using System.Drawing;

public class Main{
        /// ------------------------------------------------------------------------------------
      /// <summary>
      /// Takes and image and converts it to a disabled-looking image.
      /// </summary>
      /// ------------------------------------------------------------------------------------
      public static Image MakeDisabledImage(Image image, Color clrBase)
      {//from   w w  w  .  java  2s. c  o m
         Bitmap bmp = new Bitmap(image);
         Color notSoDark = Color.FromArgb(210, SystemColors.ControlDark);

         for (int x = 0; x < bmp.Width; x++)
         {
            for (int y = 0; y < bmp.Height; y++)
            {
               Color clr = bmp.GetPixel(x, y);

               if (clr != clrBase && clr.ToArgb() != 0)
               {
                  float brightness = clr.GetBrightness();
                  bmp.SetPixel(x, y, (brightness > 0.7 ? clrBase : notSoDark));
               }
            }
         }

         return bmp;
      }
}

Related Tutorials