Java: Counting number of pixels with Specific RGB Value

CrazyImpling

New Member
Reaction score
3
How would I count the number of pixels that have the RGB value of 153, 184, 226 that are on the screen?
 

holy_spirit

New Member
Reaction score
25
may you use this code (I code it in C#.NET)
it too close to JAVA syntax

this code takes an existing img and looping over all pixels inside it

all you have to do is to customize it as you want, in JAVA, or you may implement it as a method !

Note : Bitmap, Color is a .NET classes
Code:
         int count = 0;//Counter to count pixels 
         Bitmap b = new Bitmap("123.jpg");//Getting the image.
         Color c;

         //Looping over all pixels
         for (int i = 0; i < b.Width; i++)
         {
            for (int j = 0; j < b.Height; j++)
            {
               c = b.GetPixel(i, j);//Get the current pixel.

               if (c.R == 153 && c.G == 184 && c.B == 226)//Checking pixel
               { 
                  count++;//increase counter
                  //Do what ever you want, you have got the pixel that have
                  // R = 153 AND G = 184 AND B = 226
               }
            }
         }

Is that your question !!
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top