Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A black capture usually means the program is reading the wrong display protocol, not that PNG encoding failed. xwd reads X11 windows through DISPLAY; Java Robot reads screen pixels subject to desktop permissions and XTEST support. Native Wayland content must be captured through the permissioned XDG Screenshot or ScreenCast portals. Identify your session first, then use the matching path.

On X11, verify DISPLAY, capture the root window or the correct window ID/name, and test the saved pixels. On Wayland, stop trying to make xwd read compositor-owned pixels and use a portal. XWayland applications add a third case where logical and device-pixel coordinates can disagree, especially on HiDPI displays.

Why an xwd or Robot image is black

The tools do not capture the desktop in the same way.

xwd is an X11 reader

The X.Org utility is an “X Window System window dumping utility.” It selects an X display through DISPLAY and can dump a window by ID, a window by name, or the root window. Its -screen mode reads through the root window, which matters when overlapping or independent popup windows are visible. It cannot use Wayland’s compositor protocol to obtain native Wayland content.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents

Java Robot depends on the desktop and protocol

Robot.createScreenCapture asks the platform for screen pixels. Java can return undefined pixels or throw SecurityException when screen-read permission is unavailable. On X-Window systems, the implementation also depends on XTEST 2.2; a missing or disabled XTEST extension can make construction or capture fail. A successful PNG write therefore does not prove that the pixels were valid.

Wayland is permissioned by design

Wayland does not expose arbitrary compositor buffers to clients. The XDG Screenshot portal can request a one-shot screen, window, area, or active-window image. The ScreenCast portal creates a session, asks the user to select sources, and returns PipeWire streams for applications that need continuous or streamed capture.

1. Identify the session before changing code

Run these commands in the same graphical login that contains the window:

echo "$XDG_SESSION_TYPE"
echo "$WAYLAND_DISPLAY"
echo "$DISPLAY"
  • x11: use the xwd or Java Robot workflow below.
  • wayland: use an XDG portal first; native Wayland windows are not readable with xwd’s X11 image operation.
  • An XWayland application: treat it as a compatibility case. The client may be X11, while the compositor and screen-selection UI are Wayland.

An empty or incorrect DISPLAY is a common cause of an all-black or inaccessible xwd result. Compare it with the display used by the desktop session that actually renders the target.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

2. Capture a real X11 window with xwd

Capture the complete X11 desktop

For a baseline test, dump the root window:

xwd -root -out screen.xwd

If the command succeeds, convert the XWD file with an installed image converter:

convert screen.xwd screen.png

Use another converter if ImageMagick is not installed. Inspect screen.png before debugging your application; this separates an X11 access problem from an image-conversion problem.

Capture a specific window by ID

Obtain the target’s X11 window ID with a desktop inspection utility available on your system, then pass it to xwd:

xwd -id WINDOW_ID -out window.xwd
convert window.xwd window.png

Replace WINDOW_ID with the actual hexadecimal or numeric ID. IDs can change after an application restart, so do not cache one indefinitely.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

Capture by window title

When the title is stable, use the name selector:

xwd -name "Window title" -out window.xwd
convert window.xwd window.png

Match the title as the X11 window manager exposes it; a title changed by a document name or tab can cause the selector to miss the intended window.

When to add -screen

Add -screen when the visible result depends on overlapping windows, menus, tooltips, or other independent popup windows:

xwd -root -screen -out desktop-with-popups.xwd
convert desktop-with-popups.xwd desktop-with-popups.png

This reads through the root window rather than treating only the selected window’s own pixels as the scene.

Check the display explicitly

In a terminal attached to the correct graphical session, print DISPLAY and retry. If you launch xwd through SSH, a service, cron, or sudo, that process may have no permission to the user’s X server or may inherit a different display value. Run the command as the logged-in desktop user, and do not assume that :0 is correct.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

3. Capture with Java Robot on X11

Prerequisites

  • Run on a non-headless graphical session. A server started with no display cannot construct a useful screen-capture Robot.
  • Use screen coordinates belonging to the same GraphicsDevice that you capture. Window-manager coordinates and device pixels are not interchangeable on every desktop.
  • Allow screen capture in the desktop security policy. A denied permission can produce a SecurityException or unusable pixels.
  • Verify that XTEST 2.2 is available and enabled. Oracle’s API documentation identifies this extension as an X-Window requirement.

Minimal runnable capture program

The following program captures a rectangle, writes a PNG, and samples a pixel before blaming the encoder. Compile and run it in the graphical session:

import java.awt.AWTException;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class RobotCapture {
    public static void main(String[] args) throws IOException {
        if (args.length != 5) {
            System.err.println("Usage: java RobotCapture x y width height output.png");
            System.exit(2);
        }

        int x = Integer.parseInt(args[0]);
        int y = Integer.parseInt(args[1]);
        int width = Integer.parseInt(args[2]);
        int height = Integer.parseInt(args[3]);
        File output = new File(args[4]);

        if (GraphicsEnvironment.isHeadless()) {
            throw new IllegalStateException("A graphical, non-headless session is required");
        }

        try {
            Robot robot = new Robot();
            Rectangle area = new Rectangle(x, y, width, height);
            BufferedImage image = robot.createScreenCapture(area);
            int sample = image.getRGB(0, 0);
            if ((sample & 0x00ffffff) == 0) {
                System.err.println("Warning: sampled pixel is black; check display, permission, and XTEST");
            }
            if (!ImageIO.write(image, "png", output)) {
                throw new IOException("No PNG writer is available");
            }
            System.out.printf("Wrote %dx%d capture to %s%n", width, height, output);
        } catch (AWTException e) {
            throw new IllegalStateException("Robot is unavailable; check the display and XTEST 2.2", e);
        } catch (SecurityException e) {
            throw new IllegalStateException("Screen-capture permission was denied", e);
        }
    }
}
javac RobotCapture.java
java RobotCapture 0 0 1920 1080 desktop.png

Use the rectangle reported by your window toolkit or desktop inspection tool. Do not assume that a window’s top-left point and size are in device pixels when scaling is enabled. If the image is black, test a known colorful desktop region and inspect the sampled pixel. If the sample is non-black but the viewer shows black, investigate the viewer or conversion path instead of Robot.

4. What to do on native Wayland

Use the Screenshot portal for one image

For a one-shot capture, call the XDG Screenshot portal and request the target you need: the entire screen, a particular window, a rectangular area, or the active window. The portal normally presents a user-consent and source-selection step. A desktop portal backend must be installed and running for the request to complete.

Use ScreenCast for a stream

An application that needs repeated frames should use the XDG ScreenCast portal. Its flow creates a session, asks the user to select one or more sources, and exposes the resulting PipeWire streams. This is the appropriate path for recording or a live preview, not xwd.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

The Screenshot portal documentation describes interface version 3, while the ScreenCast documentation describes interface version 6. Availability and behavior still depend on the desktop environment’s portal backend and PipeWire session setup.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

5. XWayland and HiDPI: the awkward middle case

An XWayland client may report X11-style window information while the Wayland compositor controls the final screen. OpenJDK tracks screencast integration work for this situation. JetBrains has also documented a logical-versus-device-pixel mismatch affecting portal Robot bounds: a rectangle that is correct in Java device coordinates can be rejected or mapped to the wrong area when the compositor expects logical coordinates.

  • Test the exact JDK build and desktop combination rather than assuming all Java versions behave alike.
  • Compare the rectangle in logical coordinates with the physical pixel dimensions of the monitor.
  • Try a portal capture of the same window or area. If the portal result is correct while Robot is offset or black, the problem is coordinate translation rather than PNG output.
  • Keep XWayland compatibility separate from native Wayland. xwd may work for an XWayland window only through an X11 compatibility path; it is not a general reader of compositor-owned Wayland content.

6. Troubleshooting by symptom

Symptom Likely cause Fix
xwd -root is black or cannot open the display Wrong or inaccessible DISPLAY; command launched outside the desktop login Run as the logged-in user, print DISPLAY, and use the value belonging to the session containing the desktop.
Root capture works, named window is black or missing Stale window ID or title mismatch Discover the current ID/title again and retry; use -screen when popups or overlays are part of the visible scene.
Every native Wayland capture through xwd fails xwd uses X11 operations and cannot read compositor-owned Wayland buffers Switch to the XDG Screenshot portal for a still image or ScreenCast plus PipeWire for a stream.
Java throws SecurityException Desktop screen-read permission is denied Grant the permission in the desktop’s privacy/security controls, then restart the Java process if required.
Java throws an AWT error or returns unusable pixels Headless process, unavailable display, or unsupported/disabled XTEST 2.2 Run inside the graphical login, verify DISPLAY, and check the X server’s XTEST extension.
Robot image is shifted, clipped, or the wrong size on a scaled monitor Logical coordinates were supplied where device pixels were expected, or the reverse Map coordinates for the selected GraphicsDevice; compare with a portal capture and test at 100% scaling.
Portal request never completes Consent was denied, portal backend is missing, or PipeWire/session integration is unavailable Retry interactively, confirm a desktop portal implementation is running, and inspect the desktop’s PipeWire setup for ScreenCast.
XWD file exists but the converted image is black Conversion/viewer issue or genuinely black source pixels Try another converter and inspect raw output with a second viewer; first verify a known non-black region.

7. Reliability, performance, and operational choices

Local X11 xwd is simple and fast because it reads from the X server, but it is tied to one user session and one display authorization. Window IDs are ephemeral, and a capture started from a background service needs explicit display and authorization handling. Java Robot adds application-level coordinate and permission concerns; keep the capture rectangle small when you do not need the whole desktop, and validate pixels before uploading or processing them.

Wayland’s consent step is a reliability feature, not an error to bypass. It prevents silent screen reads and means unattended jobs need a desktop-supported, pre-authorized portal design. For continuous capture, use ScreenCast and consume PipeWire frames rather than repeatedly requesting still images. For screenshots of public web pages rather than your local desktop, an HTTP screenshot API avoids display-server setup entirely.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Or skip the browser setup

If the target is a website URL, ScreenshotNeo returns a PNG, JPEG, WebP, or PDF from one GET request. It handles the browser session for you and is useful when X11/Wayland permissions are the part failing. The API documentation is at https://screenshotneo.com/docs/.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Before capture, ScreenshotNeo accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed as clean shots, and the response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. One thousand screenshots per month are free with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account to try the URL capture.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.