• Post Reply Bookmark Topic Watch Topic
  • New Topic

Trying to use PixelGrabber, Need some help  RSS feed

 
Tanner Toyas
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
heres what i want to do. No matter what window i am in, I want it to give me the pixil color thats right in the middle of my screen. How can i do this with the image parameter? I am not doing this on a specific thing so the image parameter has to go but i dont know how to fix that. Heres my code, tell me if this is alright.


Thanks
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

We have a strict policy on display names, which must be a real first and last name with a space between. No joke names or "handles" are allowed.

Please go here and fix your display name up, pronto. Thanks, pardner!
 
Tanner Toyas
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok sorry about that, Fixed now. Any suggestions to fixing this problem? Thanks
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't use PixelGrabber to do this, but you can use the createScreenCapture() method in the java.awt.Robot class to do it; see the Javadoc for this class.
 
Tanner Toyas
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I found this script and did some research and i think I have some of it right...



What im trying to do is, make it search a 10x10 square right in the middle of my screen and print out the color. Im not sure how to print the color or anything like that. I have absolutly no expierience with the Robot class or try statments so im learning. THanks
 
Tanner Toyas
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any help? This is pretty important. Thanks
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After the createScreenCapture(), you're done with the Robot class. Now you have a BufferedImage. Look at the Javadocs for that class's APIs to learn how to get the pixels out of it.

At this point this is really a Swing/AWT thread, so I'm going to move this to that forum.
 
Tanner Toyas
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok thanks. Ok I did what I needed to using somthing that I should have used in the beggining but didnt find it. Its called getPixelColor and did exactly what I wanted to do with like 3 easy lines of code. None of this freaking screenshotting junk.

Now I have a question. I searched for a few hours but couldnt come accross anything usefull. How can I make a hotkey so when I press it, it goes into the infinite loop, and when I press it again it breaks out. I couldnt get the keylistener stuff working. This is an Application. Anyone want to give me some code samples? Thanks!

Also, here is my code and its running to slow, any way to make it run faster?





I need that delay there otherwise it laggs really bad and ends up going even slower.

Thanks!
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tanner Toyas:
ok thanks. Ok I did what I needed to using somthing that I should have used in the beggining but didnt find it. Its called getPixelColor and did exactly what I wanted to do with like 3 easy lines of code. None of this freaking screenshotting junk.

Now I have a question. I searched for a few hours but couldnt come accross anything usefull. How can I make a hotkey so when I press it, it goes into the infinite loop, and when I press it again it breaks out. I couldnt get the keylistener stuff working. This is an Application. Anyone want to give me some code samples? Thanks!

Also, here is my code and its running to slow, any way to make it run faster?





I need that delay there otherwise it laggs really bad and ends up going even slower.

Thanks!

Spawn a thread that has that loop in the "run()" method of a Runnable class when your button is pressed (if it doesn't exist yet) and inside the loop, check for a boolean that you make. then in your button's Actionlistener, make it so if it's pressed again and the runnable is not null (or is running) it calls that class's method (you make it up) "stopProcessing()" which sets the boolean to false, so in the next loop, it'll see that and break (you have to write the code to do that).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!