Gets the RGB color of a particular pixel. This function is provided for compatibility with System.Drawing. However for efficiency and flexibility you should prefer BitmapData.GetPixel.


Color GetPixel(int x, int y);

[Visual Basic]

Function GetPixel(x As Integer, y As Integer) As Color
Name Description
x The x coordinate.
y The y coordinate.
return The color.




using (Bitmap bm = new Bitmap(200, 200)) {
  using (Graphics g = Graphics.FromImage(bm)) {
    g.FillRectangle(Brushes.DarkRed, new RectangleF(0, 0, 100, 100));
    g.FillRectangle(Brushes.DarkOliveGreen, new RectangleF(100, 0, 100, 100));
    g.FillRectangle(Brushes.CornflowerBlue, new RectangleF(0, 100, 100, 100));
    g.FillRectangle(Brushes.Goldenrod, new RectangleF(100, 100, 100, 100));
  Response.Write("Top Left Color is " + bm.GetPixel(50, 50).ToString() + "<br>\r\n");
  Response.Write("Top Right Color is " + bm.GetPixel(150, 50).ToString() + "<br>\r\n");
  Response.Write("Bottom Left Color is " + bm.GetPixel(50, 150).ToString() + "<br>\r\n");
  Response.Write("Bottom Right Color is " + bm.GetPixel(150, 150).ToString() + "<br>\r\n");

The graphics file and text output that this produces are shown below.

Top Left Color is R=139, G=0, B=0
Top Right Color is R=85, G=107, B=47
Bottom Left Color is R=100, G=149, B=237
Bottom Left Color is R=218, G=165, B=32