得到像素的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;

 

posted on 2012-12-08 15:57  天上星  阅读(395)  评论(0编辑  收藏  举报

导航