Board index » delphi » finding pixels with mouse position

finding pixels with mouse position

How can I find the pixels with mouse positions over the .bmp?
is there any formulas or function ?

Sent via Deja.com http://www.deja.com/
Before you buy.

 

Re:finding pixels with mouse position


I assume you maybe talkoing about the MouseMove event or Timage..
you then use MyTColor :=  MyImage.Canvas.Pixel[X,Y]  to get it.
Quote
kara...@usa.net wrote:
> How can I find the pixels with mouse positions over the .bmp?
> is there any formulas or function ?

> Sent via Deja.com http://www.deja.com/
> Before you buy.

Re:finding pixels with mouse position


  Drop a TImage on a form:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Image1: TImage;
    procedure FormCreate(Sender: TObject);
    procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
 Y: Integer);
  private
    { Private declarations }
    ptPrev: TPoint;
    hwHint: THintWindow;
    procedure HandleIdle(Sender: TObject; var Done: Boolean);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  ptPrev.X := 0;
  ptPrev.Y := 0;
  hwHint := THintWindow.Create(self);
  Application.OnIdle := HandleIdle;
end;

procedure TForm1.HandleIdle(Sender: TObject; var Done: Boolean);
var
  pt: TPoint;
begin
  GetCursorPos(pt);
  pt := ScreenToClient(pt);
  if (pt.x > ClientWidth)  or (pt.x < 0) or
(pt.y > ClientHeight) or (pt.y < 0) then
    hwHint.ReleaseHandle;
end;

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  pt: TPoint;
  sText: String;
begin
  if (abs(x - ptPrev.X) > 1) or (abs(y - ptPrev.Y) > 1) then begin
    ptPrev.X := X;
    ptPrev.Y := Y;
    pt.x := x;
    pt.y := y + GetSystemMetrics(SM_CYCURSOR);
    pt := ClientToScreen(pt);
    sText := Format('%d,%d', [x, y]);
    hwHint.ActivateHint(Rect(pt.x, pt.y, pt.x +
hwHint.Canvas.TextWidth(sText) + 10,
pt.y + hwHint.Canvas.TextHeight(sText)), sText);
  end;
end;

end.

Quote
kara...@usa.net wrote:

> How can I find the pixels with mouse positions over the .bmp?
> is there any formulas or function ?

> Sent via Deja.com http://www.deja.com/
> Before you buy.

Other Threads