Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: How to get pixel color from 3d application

by JuR (Initiate)
on Mar 01, 2016 at 17:49 UTC ( [id://1156553]=note: print w/replies, xml ) Need Help??


in reply to How to get pixel color from 3d application

Hi it's me again :P I found a way how to get that working. at this moment code is very primitive, but it do what i want. ofc ill post the code below, because maybe someone may need it, and will modify it by himself. This is my first week with perl (and i don't know any other programming language). I have to say it again it's VERY PRIMITIVE JUST FOR TEST. GOTO made code slower. Just put it here, to check if it's works.
use Imager; use Imager::Screenshot 'screenshot'; use Win32::GuiTest qw(FindWindowLike GetWindowText SetForegroundWindow SendKeys); START: my $img = screenshot(); #make screenshot $img->write(file => 'screenshot.png', type => 'png' ) || print "Failed: ", $img->{ERRSTR} , "\n"; #write a new sreenshot o +ver old one #or send error $img=Imager->new(); #make new image $img->read(file=>'screenshot.png',type=>'png'); #read from fresh scre +enshot $color = $img->getpixel(x=>68, y=>58); #get pixel from coord +inate x,y $img1=Imager->new(); #make new image $img1->read(file=>'orginal.png',type=>'png'); #1.read from orginal +pcitrue i have made $color1 = $img1->getpixel(x=>68, y=>58); #2. before to compar +e element from $keys = (22); #3. the same coordina +tes, so when #4. window is change +on any diferent color #5. program show doin + code (else) if ($color->equals(other=>$color1)) { #if color is the same print "ok\n" #print ok, do nothing. } else { #else press key 22 from $key +s SendKeys ($keys, 100) } sleep 1; #sleep for one sec goto START; #go back and do compare aga +in with new screenshot

Replies are listed 'Best First'.
Re^2: How to get pixel color from 3d application
by tonyc (Friar) on Mar 01, 2016 at 22:32 UTC

    You can improve performance by only fetching a subset of the screen with screenshot:

    my $img = screenshot(left => 68, right => 69, top => 58, bottom => 59);

    You're also writing the screenshot to a file, then reading the same image back in again, which is a waste.

      Good idea, ill try to modify the code, thanks. If someone have a suggestions, please post it :) Thanks !

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1156553]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (8)
As of 2024-04-23 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found