0

I have a little bit localized question:

I have a Swing application in which I can add two points. What the applicaiton does is that every 100ms it saves the selected area determined by the two points from the screen (a rectangle) and compares it to a former version to see it there were any changes in that area.

So this operation does this every 100ms:

  1. Get area
  2. Create bitmap
  3. Compare with previous version (99%)

The point of this is that I need an operation to be done if the selected area changes. In 90% percent of the time that selected area is unchanged.

Is there a more efficient way in java / swing to add some kind of listener to check is a designated area changes? I tried to search for something similar but the search words are too general for this type of issue. (Or I am just stupid.)

There are pretty much millions of jars out there I was hoping there might be something similar that suits my needs.

Maroun
  • 94,125
  • 30
  • 188
  • 241
Peter Jaloveczki
  • 2,039
  • 1
  • 19
  • 35

2 Answers2

1

As shown here, createScreenCapture() can capture a BufferedImage of the pixels in the upright rectangle defined by your two points. You can loop through the pixels using getRGB() to implement any desired heuristic. Your chosen approach to detect a scene change depends on the goal. As a simple concrete example, you could use getHSBColor() to find changes in brightness. More examples may be found in ImageJ.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
1

If by 'change' you mean 'a significant change in a screen's display', then I would think that this method is the best way to go. Any other 'screen change listener' would probably have to implement the same thing.

PS: perhaps you could increase the efficiency by only testing some of the pixels for changes e.g. randomly pick 1 out of 10 pixels and only compare those.

kexu
  • 304
  • 2
  • 8