0

I am making an application that searches the screen for a specific image. I read the picture (file) I am scanning for and convert it to a buffered image, then to an int[] so I can process it faster. I also use the robot class to take a screenshot and convert to an int[].

While running code in Eclipse and having the files in the source folder, I don't have any problems. But after exporting my code to a runnable jar file, my scanning methods no longer work. I think it might have something to do with compression because my pictures need to be exactly how they were taken.

The only success I have had with a "finished format" is by exporting the jar normally, and using a folder in the same directory called images to hold the files. Using this code:

File img = new File(System.getProperty("user.dir") + File.separator + "images" + File.separator + "Close.bmp");

When running directly from eclipse I can simply do this:

File img = new File(src/Close.bmp);

Any suggestions? Maybe some tips/settings on exporting jars?

Alexey
  • 2,542
  • 4
  • 31
  • 53
Gibsdev
  • 1
  • 1

1 Answers1

0

You have various options:

  • probably the easiest is to put the image in the classpath, i.e. deploy it with your class files, probably within a jar file. The drawback is that you can't replace the image (as long as you don't want your user to fiddle with the classpath)

  • place it relative to the user.dir as you have done, in this case you need to understand what the user.dir actually is: The working directory from which your application got started. It will differ depending on how you start it.

  • another option is to use a path relative to user.home which is your home directory.

Community
  • 1
  • 1
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348