-
Bug
-
Resolution: Duplicate
-
P2
-
None
-
7
-
x86
-
linux
Platform: Linux - FAILS
Windows - PASSES
JDK: 7
Problem:
When a window has bg color with alpha component set to zero it is transparent visually, but java.awt.Robot on Linux considers it BLACK.
Please see the following code sample:
Two windows are created red on the front, green in background. Color of the foreground one is being set to new Color(123, 123, 123, 0) - it disappears visually but the robot considers it black. BTW, it is interesting to play with opacity as having zero opacity and NON-transparent background will let robot experience transparency.
---------------------------------------------------------------------------------------------------
import javax.swing.*;
import java.awt.*;
public class BlindRobot {
public static void main(String[] args) throws Exception {
System.out.println("started");
final Window[] window = new Window[1];
final Window[] bgWindow = new Window[1];
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
bgWindow[0] = new Window(null);
bgWindow[0].setSize(100, 100);
bgWindow[0].setLocationRelativeTo(null);
bgWindow[0].setBackground(Color.GREEN);
bgWindow[0].setVisible(true);
bgWindow[0].toFront();
window[0] = new Window(null);
window[0].setSize(100, 100);
// centering window on screen
window[0].setLocationRelativeTo(null);
window[0].setBackground(Color.RED);
window[0].setVisible(true);
window[0].setAlwaysOnTop(true);
window[0].toFront();
}
});
Thread.sleep(3000);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
GraphicsDevice device = window[0].getGraphicsConfiguration().getDevice();
System.out.println("PERPIXEL_TRANSLUCENT = " + device
.isWindowTranslucencySupported(GraphicsDevice
.WindowTranslucency.PERPIXEL_TRANSLUCENT));
System.out.println("TRANSLUCENT = " + device
.isWindowTranslucencySupported(GraphicsDevice
.WindowTranslucency.TRANSLUCENT));
window[0].setOpacity(0f);
final Color transparentColor = new Color(123, 123, 123, 0);
// COMMENT THIS TO GET GREEN ON LINUX
window[0].setBackground(transparentColor);
}
});
Thread.sleep(3000);
int zeroX = window[0].getX();
int zeroY = window[0].getY();
java.awt.Robot robot = new java.awt.Robot(window[0].getGraphicsConfiguration().getDevice());
System.out.println("createScreenCapture = " + new Color(robot.createScreenCapture
(new Rectangle(zeroX + 10, zeroY + 10, 1, 1)).getRGB(0, 0)));
System.out.println("pixelColor = " + robot.getPixelColor(zeroX
+ 10, zeroY + 10));
Thread.sleep(3000);
window[0].dispose();
bgWindow[0].dispose();
}
}
---------------------------------------------------------------------------------------------------
The result will be:
[stt-robot@stt-119]$ /set/java/re/jdk/7/promoted/latest/binaries/linux-i586/bin/java -cp . BlindRobot
started
PERPIXEL_TRANSLUCENT = true
TRANSLUCENT = true
createScreenCapture = java.awt.Color[r=0,g=0,b=0]
pixelColor = java.awt.Color[r=0,g=0,b=0]
Windows - PASSES
JDK: 7
Problem:
When a window has bg color with alpha component set to zero it is transparent visually, but java.awt.Robot on Linux considers it BLACK.
Please see the following code sample:
Two windows are created red on the front, green in background. Color of the foreground one is being set to new Color(123, 123, 123, 0) - it disappears visually but the robot considers it black. BTW, it is interesting to play with opacity as having zero opacity and NON-transparent background will let robot experience transparency.
---------------------------------------------------------------------------------------------------
import javax.swing.*;
import java.awt.*;
public class BlindRobot {
public static void main(String[] args) throws Exception {
System.out.println("started");
final Window[] window = new Window[1];
final Window[] bgWindow = new Window[1];
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
bgWindow[0] = new Window(null);
bgWindow[0].setSize(100, 100);
bgWindow[0].setLocationRelativeTo(null);
bgWindow[0].setBackground(Color.GREEN);
bgWindow[0].setVisible(true);
bgWindow[0].toFront();
window[0] = new Window(null);
window[0].setSize(100, 100);
// centering window on screen
window[0].setLocationRelativeTo(null);
window[0].setBackground(Color.RED);
window[0].setVisible(true);
window[0].setAlwaysOnTop(true);
window[0].toFront();
}
});
Thread.sleep(3000);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
GraphicsDevice device = window[0].getGraphicsConfiguration().getDevice();
System.out.println("PERPIXEL_TRANSLUCENT = " + device
.isWindowTranslucencySupported(GraphicsDevice
.WindowTranslucency.PERPIXEL_TRANSLUCENT));
System.out.println("TRANSLUCENT = " + device
.isWindowTranslucencySupported(GraphicsDevice
.WindowTranslucency.TRANSLUCENT));
window[0].setOpacity(0f);
final Color transparentColor = new Color(123, 123, 123, 0);
// COMMENT THIS TO GET GREEN ON LINUX
window[0].setBackground(transparentColor);
}
});
Thread.sleep(3000);
int zeroX = window[0].getX();
int zeroY = window[0].getY();
java.awt.Robot robot = new java.awt.Robot(window[0].getGraphicsConfiguration().getDevice());
System.out.println("createScreenCapture = " + new Color(robot.createScreenCapture
(new Rectangle(zeroX + 10, zeroY + 10, 1, 1)).getRGB(0, 0)));
System.out.println("pixelColor = " + robot.getPixelColor(zeroX
+ 10, zeroY + 10));
Thread.sleep(3000);
window[0].dispose();
bgWindow[0].dispose();
}
}
---------------------------------------------------------------------------------------------------
The result will be:
[stt-robot@stt-119]$ /set/java/re/jdk/7/promoted/latest/binaries/linux-i586/bin/java -cp . BlindRobot
started
PERPIXEL_TRANSLUCENT = true
TRANSLUCENT = true
createScreenCapture = java.awt.Color[r=0,g=0,b=0]
pixelColor = java.awt.Color[r=0,g=0,b=0]
- duplicates
-
JDK-6903034 java.awt.Robot.createScreenCapture() doesn't work for translucent windows
-
- Closed
-
- relates to
-
JDK-7043845 Robot should be able take screenshots with translucent windows
-
- Closed
-