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

Posted on 2011-03-11
Medium Priority
Last Modified: 2013-11-22
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?
Question by:cr38
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 35106794
Check out the ScanLine function

See http://edn.embarcadero.com/article/29173
LVL 13

Accepted Solution

ThievingSix earned 332 total points
ID: 35110516
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);

Author Comment

ID: 35112455
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...
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 13

Assisted Solution

ThievingSix earned 332 total points
ID: 35112538
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.

Author Comment

ID: 35114311
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;

Author Comment

ID: 35114431
Nevermind! I was being dumb and not initialising the image... neede the line Image1 := TBitMap.Create;

Thanks for your help everyone!

Assisted Solution

RezaSadigh earned 168 total points
ID: 35114444
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

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: When experiencing some peculiar problem with the functioning of your PC, how many times has it happened that you look for a solution and even google can’t help? It could be that you are one of the only few people on earth who ma…
pc, laptop  monitor connection configurations
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question