On Wed, 30 Oct 2024 14:30:56 GMT, Naveen Narayanan <d...@openjdk.org> wrote:
>> test/jdk/java/awt/Robot/ScreenCaptureRobotTest.java line 94: >> >>> 92: >>> 93: Point pnt = canvas.getLocationOnScreen(); >>> 94: Rectangle rect = new Rectangle(pnt.x + 10, pnt.y + 10, 200, >>> 100); >> >> Why are coordinates of the start of the canvas are offset by 10 pixels but >> the size isn't? The image is 200×100, then you capture 10 pixels on the >> right and bottom which belong to whatever is on the screen in this area. > > @aivanov-jdk > While creating the Canvas > drawImage(realImage, 10, 10, this) > 10 offset is used. > > Hence the start point coordinates also moved by 10 pixels > for capturing. Okay, I see that you offset the image on the canvas too. If you insist on using an offset, please declare a constant `OFFSET = 10` and use it everywhere instead of the ‘magic’ numbers: when painting to canvas, and when capturing the image. You used a constant for a delay that was used once but you don't create a constant to offset the image off edges that you use in two different places. If one place is updated, the other has to be updated as well. Using a constant does it all automatically. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/21524#discussion_r1822804191