如何取得滑鼠游標所在位置的RGB顏色值(十進位, 十六進位) ? |
答題得分者是:taishyang
|
pcboy
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:177 回覆:1838 積分:1463 註冊:2004-01-13 發送簡訊給我 |
|
taishyang
站務副站長 ![]() ![]() ![]() ![]() ![]() ![]() 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
pcboy
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:177 回覆:1838 積分:1463 註冊:2004-01-13 發送簡訊給我 |
寫好了 [code delphi] unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls; type TForm1 = class(TForm) Timer1: TTimer; Edit1: TEdit; Edit2: TEdit; procedure Timer1Timer(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin Form1.Caption := 'Get Cursor RGB Value'; Timer1.Interval := 50; end; procedure TForm1.Timer1Timer(Sender: TObject); const Digits: array[0..15] of char = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); var dc:hdc; hnd:hwnd; p:Tpoint; v : Integer; R1,G1,B1 : Integer; R2,G2,B2 : String; begin hnd:=getdesktopwindow(); // dc:=getwindowdc(hnd); // //上面的2句也可以寫成dc:=getwindowdc(0) Windows.GetCursorPos(p); //Edit1.Text := InttoStr(getpixel(dc,p.X,p.Y)); v := getpixel(dc,p.X,p.Y); R1 := v div 65536; G1 := (v mod 65536) div 256; B1 := v mod 256 ; R2 := Digits[(R1 div 16)] Digits[(R1 mod 16)]; G2 := Digits[(G1 div 16)] Digits[(G1 mod 16)]; B2 := Digits[(B1 div 16)] Digits[(B1 mod 16)]; Edit1.Text := IntToStr(R1) '-' IntToStr(G1) '-' IntToStr(B1); Edit2.Text := R2 '-' G2 '-' B2; releasedc(handle,dc); end; end. [/code]
------
能力不足,求助於人;有能力時,幫幫別人;如果您滿意答覆,請適時結案! 子曰:問有三種,不懂則問,雖懂有疑則問,雖懂而想知更多則問! |
taishyang
站務副站長 ![]() ![]() ![]() ![]() ![]() ![]() 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
pcboy
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:177 回覆:1838 積分:1463 註冊:2004-01-13 發送簡訊給我 |
修改如下 (IntToHEX 就請您表演吧)
[code delphi] unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Edit2: TEdit; Timer1: TTimer; procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin Form1.Caption := 'Get Cursor RGB Value'; Timer1.Interval := 50; end; procedure TForm1.Timer1Timer(Sender: TObject); const Digits: array[0..15] of char = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); var dc:hdc; hnd:hwnd; p:Tpoint; v : Integer; R1,G1,B1 : Integer; R2,G2,B2 : String; begin hnd:=getdesktopwindow(); // dc:=getwindowdc(hnd); // //上面的2句也可以寫成dc:=getwindowdc(0) Windows.GetCursorPos(p); //Edit1.Text := InttoStr(getpixel(dc,p.X,p.Y)); v := getpixel(dc,p.X,p.Y); //R1 := v div 65536; //G1 := (v mod 65536) div 256; //B1 := v mod 256 ; R1 := GetRValue(v); G1 := GetGValue(v); B1 := GetBValue(v); R2 := Digits[(R1 div 16)] Digits[(R1 mod 16)]; G2 := Digits[(G1 div 16)] Digits[(G1 mod 16)]; B2 := Digits[(B1 div 16)] Digits[(B1 mod 16)]; //R2 := IntToHEX(R1); // Failed //R2 := (String)IntToHEX(R1); // Failed Edit1.Text := IntToStr(R1) '-' IntToStr(G1) '-' IntToStr(B1); Edit2.Text := R2 '-' G2 '-' B2; releasedc(handle,dc); end; end. [/code]
------
能力不足,求助於人;有能力時,幫幫別人;如果您滿意答覆,請適時結案! 子曰:問有三種,不懂則問,雖懂有疑則問,雖懂而想知更多則問! |
taishyang
站務副站長 ![]() ![]() ![]() ![]() ![]() ![]() 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |