DXcam - High-Performance Windows Screenshot Library

0.3.0 · active · verified Fri Apr 17

DXcam is a Python library providing high-performance screenshot capabilities specifically for Windows, leveraging the Desktop Duplication API. It's currently at version 0.3.0 and sees active development with irregular but significant updates, focusing on performance, backend options, and robustness.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes DXcam, starts capturing, grabs a single frame, and displays it using OpenCV (if installed). It includes error handling for non-Windows environments and initialization failures.

import dxcam
import cv2

# dxcam is Windows-only, so this example will only run there.
# On other OS, it will raise a RuntimeError.

try:
    # Create a DXcam instance, auto-detecting the primary display output.
    # Optionally specify output_idx, region, or device_idx.
    camera = dxcam.create()

    if camera is None:
        print("Failed to create DXcam instance. Ensure a display is connected and drivers are up to date.")
    else:
        # Start capturing frames. By default, it captures the full screen.
        camera.start(target_fps=30)

        # Grab a single frame
        frame = camera.grab()

        if frame is not None:
            print(f"Captured frame with shape: {frame.shape}, dtype: {frame.dtype}")
            # Example: Display the frame using OpenCV (requires opencv-python)
            cv2.imshow('DXcam Frame', frame)
            cv2.waitKey(1000) # Display for 1 second
            cv2.destroyAllWindows()
        else:
            print("Failed to grab a frame.")

        # Stop capturing frames when done
        camera.stop()

except RuntimeError as e:
    print(f"Error initializing DXcam: {e}. DXcam is a Windows-only library.")
except ImportError as e:
    print(f"Missing required dependency for quickstart: {e}. Try 'pip install dxcam opencv-python numpy'.")

view raw JSON →