Results 1 to 3 of 3
Thread: Newbie - Robot Class
- 11-14-2008, 02:40 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 2
- Rep Power
- 0
Newbie - Robot Class
Hello,
This is probably an easy one for an experienced Java programmer. I have a limited programming background and Java is very new to me, so the switch to an OO language is different than what I am used to. Most of my problems have been syntax related so far. I searched around this site and found a lot of information already, but I've spent spare time over two weeks searching google, forums, etc., without any more progress. As much as I'd like to figure it out on my own, eventually a person has to know when to ask for help. Anyway, what I am trying to do is make a Class that creates a .png image from a specified are using screencapture. I then want to load the image, turn it into a pixel arrary, and then compare it to other saved images to see if it is a match. So I need a class with three methods - getimage, loadimage, and cmprimage. I have been able to get the getimage to work, but I cannot get the image to load. No matter what I try, it returns null. TIA to anyone who can help me out. It does compile & run without error. Here is some code:
//This works and saves the correct png image
public void getimage () throws AWTException, IOException{
//get image
Robot robot = new Robot();
Rectangle rect = new Rectangle(1075,556,30,14);
BufferedImage scn = robot.createScreenCapture(rect);
// Save image as PNG
File file = new File("test.png");
ImageIO.write(scn, "png", file);
System.out.println("wrote new rect png file");
}
//This is where I get a null value all the time. If I try and do anything with img, it has a null value
public void loadimage() throws IOException, AWTException{
InputStream img = getClass().getResourceAsStream("test.png");
BufferedImage bi = ImageIO.read(img);
System.out.println("read buffered image");
}Last edited by drasgear; 11-14-2008 at 02:42 AM.
-
Your problem may be that the current directory for standard IO is different for that used by the getResourceAsStream. Why not load the image via ImageIO.read("test.png")?
- 11-14-2008, 04:46 PM #3
Member
- Join Date
- Nov 2008
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
newbie newbie newbie
By krislogy in forum New To JavaReplies: 9Last Post: 08-15-2008, 12:28 AM -
Capturing video with Robot
By russ2620 in forum AWT / SwingReplies: 0Last Post: 06-03-2008, 04:49 PM -
Robot Class
By Jessie Madman in forum New To JavaReplies: 3Last Post: 05-15-2008, 04:13 AM -
Newbie
By CSnoob87 in forum IntroductionsReplies: 2Last Post: 02-18-2008, 08:49 AM -
Robot Class
By jfredrickson in forum New To JavaReplies: 2Last Post: 07-11-2007, 09:00 AM
Bookmarks