得到像素的R、G、B值

在窗体 上加载一图片,并在图片的点击事件中MouseDown(其它的也可)写如下代码:

C#:

 private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            Bitmap b =(Bitmap) pictureBox1.Image;
            Color cc=  b.GetPixel(e.X, e.Y);
            textBox1.Text = cc.R.ToString();
            textBox2.Text = cc.G.ToString();
            textBox3.Text = cc.B.ToString();

        }

Delphi:

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  color:TColor;
begin
  color:=GetPixel(self.Canvas.Handle,x,y);
  Edit1.Text:=IntToStr(GetRValue(color));
  Edit2.Text:=IntToStr(GetGValue(color));
  Edit3.Text:=IntToStr(GetBValue(color));
end;
原文地址:https://www.cnblogs.com/yagzh2000/p/2808990.html