• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1323
  • Last Modified:

Does anyone know how to do a fast Delphi Getpixel anywhere on the screen?

I am busy doing some delphi coding. I am doing a block getpixel (about 50x50 pixels). It is really slow and I need to speed up the process. I am running Windows 7 64 Bit ultimate but in my mind it is currently way slower than it should be. Could someone please help?
3 Solutions
Check out the ScanLine function

See http://edn.embarcadero.com/article/29173
I'm not sure how much faster this will be than getting the screenshot then using scanlines but you can try


Specifically -

procedure ScreenShot(x: Integer;  y: Integer; Width: Integer; Height: Integer;  bm: TBitMap);
cr38Author Commented:
Thanks guys...but "ThievingSix" I have a question...If I screenshot the pixel I assume I set the width and height to 1 in that procedure and x and y are the co-ordinates. But now it puts the information in the TBitMap handle. Is that the same as TColor because I called a single pixel? Sorry a bit of a noob at this...
Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Ah, I thought you wanted to get 50x50 block of pixels. You can set the width and height to 50 and the x, and y to the required spots.

You can then do your pixel search with either scanlines or with x/y values in the smaller blcok you made from the first step.
cr38Author Commented:
Here is my code and its breaking...

Function IsButton : Boolean;

 LoopX,LoopY : Integer;
 TotalColour,MyColour : Real;
 Counter : Integer;
 ImageCanvas : TCanvas;
 CheckResult : Boolean;
 Image1 : TBitMap;
 Flag : DWord;

 CheckResult :=False;
 Counter :=0;

 For LoopX := 0 To 10 Do
  For LoopY := 0 To 10 Do
   MyColour:=(GetRValue(Image1.Canvas.Pixels[LoopX,LoopY])*65536) +(GetGValue(Image1.Canvas.Pixels[LoopX,LoopY])*256)+GetBValue(Image1.Canvas.Pixels[LoopX,LoopY]);
   TotalColour :=TotalColour + MyColour;
 If Round(TotalColour / Counter) = 9979744 Then
  CheckResult := True;
cr38Author Commented:
Nevermind! I was being dumb and not initialising the image... neede the line Image1 := TBitMap.Create;

Thanks for your help everyone!
Hi my friend,
As you mentioned, Using Canvas.Pixels is too slow. I recommend that use
1- Graphic32: http://www.graphics32.org
2-ImageEN: http://www.hicomponents.com/
both of them are free.
Best regards
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now