如何获得panel内鼠标经过点的颜色值?(100分)

  • 主题发起人 主题发起人 kanghongchao
  • 开始时间 开始时间
K

kanghongchao

Unregistered / Unconfirmed
GUEST, unregistred user!
在panel里采集视频,我想鼠标在panel里移动,就可以显示出经过的各点的颜色值RGB?如何做 请给出具体代码 谢谢
 
给分吧!
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Button1: TButton;
ColorDialog1: TColorDialog;
Shape1: TShape;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Image1: TImage;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
private
procedure AMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.AMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
Color: TColor;
R,G,B: Byte;
ABitmap:TBitmap;
begin
if not (sender is TImage) then exit;
ABitmap:=TBitmap.Create;
ABitmap.Assign((sender as TImage).Picture.Bitmap);
Color := ABitmap.Canvas.Pixels[x, y];
edit1.Text := inttostr(GetRValue(Color));//R
edit2.Text := inttostr(GetGValue(Color));//G
edit3.Text := inttostr(GetBValue(Color));//B
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if Opendialog1.Execute then
begin
Image1.Picture.LoadFromFile(Opendialog1.FileName);
Image1.OnMouseMove:=AMouseMove;
end;
end;
 
我不是通过载入图像 而是panel里一直都有采集到的视频图像
在Image里用Image1.Picture.Bitmap.Canvas.Pixels[x,y]就可以
可是在panel里用什么?
你能做一下修改吗?如果可行 我可以再加分
 
一人50分.
procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
dc:HDC;
color:TColor;
begin
dc:=GetDC(Panel1.Handle);
color:=GetPixel(dc,x,y);
edit1.Text := inttostr(GetRValue(Color));//R
edit2.Text := inttostr(GetGValue(Color));//G
edit3.Text := inttostr(GetBValue(Color));//B
end;
 
GetPixel(dc,x,y); 是最好的,可以获得整个屏幕的象素
如: inttohex(GetPixel(GetDC(0),x,y),6);
 
已送分
谢谢
 
后退
顶部