Checks if the given bitmap is a single color. If the result is true, its color will be stored in the second parameter. - CSharp System.Drawing

CSharp examples for System.Drawing:Bitmap

Description

Checks if the given bitmap is a single color. If the result is true, its color will be stored in the second parameter.

Demo Code


using System.Windows.Forms;
using System.Text;
using System.Linq;
using System.Drawing;
using System.Collections.Generic;
using System;/*  w  w  w  .jav a  2  s .  c o m*/

public class Main{
        /// <summary>
      /// Checks if the given bitmap is a single color. If the result is true, its color will be stored in the second parameter.
      /// </summary>
      public static bool IsSolidColor(Bitmap bmp, out Color c) {
         c = bmp.GetPixel(0, 0);
         for (int y = 0; y < bmp.Height; y++) {
            for (int x = 0; x < bmp.Width; x++) {
               if (bmp.GetPixel(x, y) != c) {
                  return false;
               }
            }
         }
         return true;
      }
}

Related Tutorials