Solved

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

Posted on 2011-03-11
7
1,093 Views
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?
0
Comment
Question by:cr38
7 Comments
 
LVL 7

Expert Comment

by:ebob42
ID: 35106794
Check out the ScanLine function

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

Accepted Solution

by:
ThievingSix earned 83 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

http://www.swissdelphicenter.ch/torry/showcode.php?id=259

Specifically -

procedure ScreenShot(x: Integer;  y: Integer; Width: Integer; Height: Integer;  bm: TBitMap);
0
 

Author Comment

by:cr38
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...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 13

Assisted Solution

by:ThievingSix
ThievingSix earned 83 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.
0
 

Author Comment

by:cr38
ID: 35114311
Here is my code and its breaking...

Function IsButton : Boolean;

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

Begin
 CheckResult :=False;
 TotalColour:=0;
 Counter :=0;


 ScreenShot(580,540,11,11,Image1);
 For LoopX := 0 To 10 Do
  For LoopY := 0 To 10 Do
  Begin
   MyColour:=(GetRValue(Image1.Canvas.Pixels[LoopX,LoopY])*65536) +(GetGValue(Image1.Canvas.Pixels[LoopX,LoopY])*256)+GetBValue(Image1.Canvas.Pixels[LoopX,LoopY]);
   TotalColour :=TotalColour + MyColour;
   Counter:=Counter+1;
  End;
 If Round(TotalColour / Counter) = 9979744 Then
 Begin
  CheckResult := True;
 End;
 MsgBox(FloatToStr(TotalColour/Counter),'Awesome',Flag);
 IsButton:=CheckResult;
End;
0
 

Author Comment

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

Thanks for your help everyone!
0
 
LVL 2

Assisted Solution

by:RezaSadigh
RezaSadigh earned 42 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
or
2-ImageEN: http://www.hicomponents.com/
both of them are free.
Best regards
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Time lapse between the recorded video files 16 127
Solar enabled power bank 5 68
control image tags in a string ? 12 111
Delphi and Access based Enumeration 9 47
System overheating may become a serious problem if not taken care of at the proper time. I am writing this article because I faced a similar problem. Intro All electronic devices produce heat, but computers are a special case - the processors bo…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now