| | |
Select moving pixels
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
Hi Guys,
I have been googling for a while, I think the problem is I don't know what I'm looking for is called.
I want to write a program that watches my screen (I assume it would take screen shots really fast) and then analyzes them finding the moving pixels.
If anyone could point me in the right direction I would appreciate that very much.
Thanks
PO
I have been googling for a while, I think the problem is I don't know what I'm looking for is called.
I want to write a program that watches my screen (I assume it would take screen shots really fast) and then analyzes them finding the moving pixels.
If anyone could point me in the right direction I would appreciate that very much.
Thanks
PO
History will be kind to me for I intend to write it.
---------------------------------- Sir Winston Churchill
---------------------------------- Sir Winston Churchill
Hey guys
I am using this to take the screen shot, and what I have is another image that is 150px by 150px that I wanna scan through the screen shot and see if I can find the small image.
Can anyone help me?
I am using this to take the screen shot, and what I have is another image that is 150px by 150px that I wanna scan through the screen shot and see if I can find the small image.
Can anyone help me?
java Syntax (Toggle Plain Text)
package toolsPKG; import java.awt.*; import java.awt.image.*; import java.io.*; import javax.imageio.*; public class Screenshot { private static String[] argument = new String[2]; public Screenshot(){} public void TakeScreen(String waitSecs, String fileName) throws Exception{ argument[0] = waitSecs; argument[1] = fileName; // make sure we have exactly two arguments, // a waiting period and a file name if (argument.length != 2) { System.err.println("Usage: java Screenshot " + "WAITSECONDS OUTFILE.png"); System.exit(1); } // check if file name is valid String outFileName = argument[1]; if (!outFileName.toLowerCase().endsWith(".png")) { System.err.println("Error: output file name must " + "end with \".png\"."); System.exit(1); } // wait for a user-specified time try { long time = Long.parseLong(argument[0]) * 1000L; System.out.println("Waiting " + (time / 1000L) + " second(s)..."); Thread.sleep(time); } catch(NumberFormatException nfe) { System.err.println(argument[0] + " does not seem to be a " + "valid number of seconds."); System.exit(1); } // determine current screen size Toolkit toolkit = Toolkit.getDefaultToolkit(); Dimension screenSize = toolkit.getScreenSize(); Rectangle screenRect = new Rectangle(screenSize); // create screen shot Robot robot = new Robot(); BufferedImage image = robot.createScreenCapture(screenRect); // save captured image to PNG file /* ImageIO.write(image, "png", new File(outFileName)); // give feedback System.out.println("Saved screen shot (" + image.getWidth() + " x " + image.getHeight() + " pixels) to file \"" + outFileName + "\"."); // use System.exit if the program hangs after writing the file; // that's an old bug which got fixed only recently // System.exit(0); */ } }
Last edited by PhiberOptik; Apr 12th, 2009 at 9:02 pm. Reason: forgot to add the code
History will be kind to me for I intend to write it.
---------------------------------- Sir Winston Churchill
---------------------------------- Sir Winston Churchill
•
•
Join Date: Sep 2008
Posts: 1,637
Reputation:
Solved Threads: 206
Huh? Are you saying you want to compare the images to see if they are duplicates? If so, you can do that by comparing pixel by pixel, since a blown up image converts every 1 pixel to 4 pixels or something like that. I don't know much about it, but I "studied" (read: didn't pay attention) to a similar topic in class, so I could point you towards some resources that would be helpful if that is what you're trying to accomplish.
okay scrap the above.
Heres what I got:
I'm using
Any ideas how I can convert
Heres what I got:
I'm using
BufferedReader.getRGB(x, y); and it gives me -10452992 but what I really want is the seperate color codes, ie R=255 G=255 B=255 .Any ideas how I can convert
-10452992 to color codes? History will be kind to me for I intend to write it.
---------------------------------- Sir Winston Churchill
---------------------------------- Sir Winston Churchill
I made this script up but it returns
AAAH I'm going crazy!
Thanks for the help!
java.awt.Color[r=0,g=0,b=0] java Syntax (Toggle Plain Text)
private static byte maskByteOne = (byte)(-128 << 24); private static byte maskByteTwo = (byte)(-128 << 16); private static byte maskByteThree = (byte)(-128 << 8); private static byte maskByteFour = (byte)(-128); public static Color colorFromArgb(int argb) { byte r = (byte)((argb & maskByteOne) >> 24); byte g = (byte)((argb & maskByteTwo) >> 16); byte b = (byte)((argb & maskByteThree) >> 8); byte a = (byte)((argb & maskByteFour)); return new Color(r,g,b,a); }
AAAH I'm going crazy!
Thanks for the help!
History will be kind to me for I intend to write it.
---------------------------------- Sir Winston Churchill
---------------------------------- Sir Winston Churchill
•
•
Join Date: Apr 2008
Posts: 1,016
Reputation:
Solved Threads: 150
You can get an aray of pixels to do your scanning/looking for algorithms by using the PixelGrabber class (I've attached some code I wrote earlier that will give you a head start).
To decode an RGB pixel int, this works:
To decode an RGB pixel int, this works:
java Syntax (Toggle Plain Text)
int pixel = // whatever, eg getPixel(x, y); // int alpha = (pixel >> 24) & 0xff; int r = (pixel >> 16) & 0xff; int g = (pixel >> 8) & 0xff; int b = (pixel) & 0xff;
java Syntax (Toggle Plain Text)
public class PixelArray{ // useful (?) stuff for image processing via PixelGrabber's pixel array private Image image; private int w, h; private int[] pixels; public PixelArray(Image im) { image = im; w = image.getWidth(null); h = image.getHeight(null); pixels = new int[w * h]; PixelGrabber pxg = new PixelGrabber(image, 0, 0, w, h, pixels, 0, w); try { pxg.grabPixels(); } catch (InterruptedException e) { e.printStackTrace(); } } public int getPixel(int x, int y) { return pixels[x + y * w]; } }
![]() |
Similar Threads
- Turtle graph (Python)
- Display problem! desktop looks shrunk (Monitors, Displays and Video Cards)
- Display problem! desktop looks shrunk (Windows 95 / 98 / Me)
Other Threads in the Java Forum
- Previous Thread: Netbeans question
- Next Thread: for loop error
| Thread Tools | Search this Thread |
Tag cloud for Java
affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth businessintelligence chat class classes client code component database desktop draw ebook eclipse encode equation error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer intersect j2me java javaexcel javaprojects jmf jni jpanel julia linked linux list loop mac main map method methods mobile netbeans newbie number object online open-source oracle parameter print problem program programming project properties recursion reference replaysolutions rotatetext scanner score screen scrollbar server set size sms socket sort sql string superclass swing template test threads time tree windows xstream






