title: Making a dot in the center of a bitmap C#
body: <p>I have tried looking for this but I can't seem to find any code to work with a bitmap or a png. I am doing some calculations to find the center of a cluster of black points from a binarized image. I want to know if the center is correct by drawing a red dot at the center points. All the graphics methods I used draw the red dot on the form not on the saved image itself. How can I draw a red dot on the binarized image? (Binarized basically means applying a threshold to an image to get where the light is). I will attach my code below. Basically I press a button and then some grayscale algorithm happens then I apply Bernsen threshold, and save that image as "result". Then I go over the image result and do my calculations. I want to draw a red dot with the XCenter and YCenter on result.</p>
  
  <pre><code>    //Function for going through the image in windows of 2 pixels
      private ArrayList getNeighbours(int xPos, int yPos, Bitmap bitmap)
      {
          ArrayList neighboursList = new ArrayList();
  
          int xStart, yStart, xFinish, yFinish;
  
          int pixel;
  
          xStart = xPos - 2;
          yStart = yPos - 2;
  
          xFinish = xPos + 2;
          yFinish = yPos + 2;
  
  
          for (int y = yStart; y &lt;= yFinish; y++)
          {
              for (int x = xStart; x &lt;= xFinish; x++)
              {
  
                  if (x &lt; 0 || y &lt; 0 || x &gt; (bitmap.Width - 1) || y &gt; (bitmap.Height - 1))
                  {
                      continue;
                  }
                  else
                  {
                      pixel = bitmap.GetPixel(x, y).R;
  
                      neighboursList.Add(pixel);
                  }
              }
          }
  
          return neighboursList;
      }
  
  
   private void button5_Click_1(object sender, EventArgs e)
      {
          for (int i = 48; i &lt; 49; i++)
          {
              BlackPoints = 0;
              SumX = 0;
              SumY = 0;
              Xcenter = 0;
              Ycenter = 0;
  
              pictureBox2.Image = System.Drawing.Image.FromFile(@"C:\Users\Salma\Desktop\Images\" + i + ".png");
              Bitmap image = new Bitmap(pictureBox2.Image);
  
  
              /////////////Gray Scale First////////////////////
              byte red, green, blue, grayscale;
  
              for (int y = 0; y &lt; image.Height; y++)
              {
                  for (int x = 0; x &lt; image.Width; x++)
                  {
                      red = image.GetPixel(x, y).R;
                      green = image.GetPixel(x, y).G;
                      blue = image.GetPixel(x, y).B;
  
                      grayscale = Convert.ToByte((red + green + blue) / 3);
                      image.SetPixel(x, y, Color.FromArgb(grayscale, grayscale, grayscale));
                  }
  
              }
              //////////////////////////////////////////////
              //////////////Bernsen Threshold///////////////
              Bitmap result = new Bitmap(pictureBox2.Image);
  
              int iMin, iMax, t, c, contrastThreshold, pixel;
  
              contrastThreshold = 110;
  
              ArrayList list = new ArrayList();
  
              for (int y = 0; y &lt; image.Height; y++)
              {
                  for (int x = 0; x &lt; image.Width; x++)
                  {
                      list.Clear();
  
                      pixel = image.GetPixel(x, y).R;
                      list = getNeighbours(x, y, image);
                      list.Sort();
  
                      iMin = Convert.ToByte(list[0]);
                      iMax = Convert.ToByte(list[list.Count - 1]);
  
                      t = ((iMax + iMin) / 2);
  
                      c = (iMax - iMin);
  
                      if (c &lt; contrastThreshold)
                      {
                          pixel = ((t &gt;= 160) ? 0 : 255);
                      }
                      else
                      {
                          pixel = ((pixel &gt;= t) ? 0 : 255);
                      }
                      result.SetPixel(x, y, Color.FromArgb(pixel, pixel, pixel));
  
                  }
  
              }
  
              pictureBox3.Image = result;
              result.Save("C:\\Users\\Salma\\Desktop\\Threshold\\" + i + ".png");
  
              for (int h = 0; h &lt; result.Height; h++)
              {
                  for (int w = 0; w &lt; result.Width; w++)
                  {
                      //Get the color at each pixel
                      Color now_color = result.GetPixel(w, h);
  
                      //Compare Pixel's Color ARGB property with the picked color's ARGB Property 
                      if (now_color.ToArgb() == Color.Black.ToArgb())
                      {
  
                          SumX += w;
                          SumY += h;
  
                          BlackPoints++;
  
  
                          Xcenter = SumX / BlackPoints;
                          Ycenter = SumY / BlackPoints;
  
  
  
                      }
                  }
              }
  
          }
      }
  </code></pre>