C has no portable screenshot function. A C program must call the capture API provided by its operating system (or desktop session), obtain pixels, and encode them as PNG, JPEG, WebP, BMP or another format. Choose the backend from three decisions: your platform, whether you need one still image or a continuous stream, and whether the target is a full display, a window or a region.
The examples below show a complete X11 still-image program and the platform-specific API choices for Windows, macOS, Wayland and QNX. They are application-level captures, not instructions for taking a screenshot manually with a keyboard shortcut.
Choose the capture path before writing C
| Target | Recommended API or approach | Important constraints |
|---|---|---|
| Windows, one user-selected display or window | Windows.Graphics.Capture | Displays a system picker; translate the documented C# example through your chosen Windows ABI or projection. |
| Windows, basic Win32 bitmap | GDI device contexts and bitmaps | Useful for a one-off bitmap; it is a Win32 API, not portable C. |
| Windows, continuous frames | DXGI Desktop Duplication | Handle BGRA surfaces, dirty and moved regions, rotation, pointer composition and frame-release errors. |
| macOS, one frame | ScreenCaptureKit and SCScreenshotManager | Request Screen Recording permission; C callers need Objective-C interoperability. |
| macOS, stream | ScreenCaptureKit and SCStream | Use the system content-sharing picker where possible. |
| Linux on X11 | X11 image APIs such as XGetImage | Works only in an X11 session and requires X11 development libraries. |
| Linux on Wayland | XDG Desktop Portal or a desktop-specific compositor interface | Session policy and user consent are part of the workflow; an X11 snippet is not a Wayland solution. |
| QNX display | QNX Screen API | Display capture requires a privileged display-manager context and effective user ID root. |
A cross-platform C product normally defines one internal interface such as capture_frame(), then supplies separate backends. The snapx C project illustrates this architecture with platform-dependent backends; it should not be treated as a universal API contract.
Linux X11: a complete C still screenshot
The following program captures the root window in an X11 session and writes a binary PPM file. PPM is intentionally used because it requires no third-party image encoder. Convert it to PNG or JPEG afterward with an image library or command-line converter. This program does not work on a native Wayland session.
#1 Best Overall
- 【1080P 60FPS Video Capture Card】 This HDMI game capture card is based on USB3.0 high speed transmission port, input resolution up to 4K@30HZ, output resolution up to 2K@30Hz or 1920×1080@60Hz. Type c and USB interface can meet most of the devices in daily life. Easily meet the online capture, real-time recording, online meetings, live gaming and other functions, so you have a better visual enjoyment. Note: For capture use only; requires capture software to function and is not intended for direct screen casting to a monitor or TV
- 【Ultra Low Latency Screen Sharing】 HDMI capture card is made of good quality aluminum alloy with strong heat dissipation, allowing you to enjoy ultra low latency while live gaming or video recording or live streaming, avoiding blue screens and lag. This HDMI to USBC capture card supports easy recording of good quality audio or HD video and transferring it to your computer or streaming platform, allowing you to record 60 fps HD video directly on your hard drive and real-time preview
- 【Plug and Play, Easy to Carry】 This HDMI 1080P video capture card does not require any additional drivers or external power supply, just plug and play for fast capture. The capture card is small and lightweight, so you can put it in your bag for emergencies, making it very portable for outdoor live streaming. It's also a great way to share content in game recording, video conference, video recorder and online teaching
- 【Wide Compatibility USB Capture Card】 Easily streams to Facebook, Youtube or Twitch. With the connection, this HDMI to USB C/3.0 video capture devices can be working on several Operating Systems and various software: Windows 7/ 8/ 10, Mac OS or above, Linux, Android, Laptop, Xbox One, PS3/PS4/PS5, Camera, DVDs, Set Top Box, Webcame, DSLR, Switch/Switch 2, TV BOX, HDTV, Potplayer/VLC, ZOOM, OBS Studio etc.
- 【Package Content & Note】 1x HD Audio Capture Card , 1x USB 3.0 to USB C Adapter (A-side 3.0, B-side 2.0), 1x user manual. Please note that you need to restart the OBS Studio software after the audio setup is complete, otherwise it will result in no sound output. When using an adapter, if the device is recognized as USB 2.0, try using the other side with the USB-C port. Simply flip the capture card and reconnect it to be recognized as USB 3.0
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <stdlib.h>
int main(void) {
Display *display = XOpenDisplay(NULL);
if (!display) {
fprintf(stderr, "Cannot open X display\n");
return 1;
}
int screen = DefaultScreen(display);
Window root = RootWindow(display, screen);
unsigned width = (unsigned)DisplayWidth(display, screen);
unsigned height = (unsigned)DisplayHeight(display, screen);
XImage *image = XGetImage(display, root, 0, 0, width, height,
AllPlanes, ZPixmap);
if (!image) {
fprintf(stderr, "XGetImage failed\n");
XCloseDisplay(display);
return 1;
}
FILE *out = fopen("screenshot.ppm", "wb");
if (!out) {
perror("screenshot.ppm");
XDestroyImage(image);
XCloseDisplay(display);
return 1;
}
fprintf(out, "P6\n%u %u\n255\n", width, height);
for (unsigned y = 0; y < height; ++y) {
for (unsigned x = 0; x < width; ++x) {
unsigned long pixel = XGetPixel(image, x, y);
unsigned char rgb[3];
rgb[0] = (unsigned char)((pixel & image->red_mask) >> 16);
rgb[1] = (unsigned char)((pixel & image->green_mask) >> 8);
rgb[2] = (unsigned char)(pixel & image->blue_mask);
fwrite(rgb, 1, 3, out);
}
}
fclose(out);
XDestroyImage(image);
XCloseDisplay(display);
return 0;
}
Compile on a system with X11 headers and libraries:
cc -O2 -Wall screenshot_x11.c -o screenshot_x11 -lX11
./screenshot_x11
The mask shifts in this short example assume the common 8-bit-per-channel layout. For unusual visuals, derive channel shifts and widths from the masks instead of assuming 16, 8 and 0. For production PNG output, use a maintained encoder and check every allocation and write result.
Capturing a window or region on X11
Replace the root window with the target window ID and pass its geometry to XGetImage. A region capture uses the same call with non-zero x, y, width and height. Finding a window under the pointer, selecting a window interactively and coping with compositing are separate X11 tasks; do not assume that a root-window image is identical to what a compositor displays.
Linux Wayland: do not reuse the X11 recipe
Wayland intentionally restricts arbitrary screen reads. A native Wayland application generally asks the desktop’s XDG Desktop Portal to let the user choose a display or window, then receives the permitted content through the session’s supported transport. Exact behavior depends on the desktop and portal implementation. Test GNOME, KDE or another target session rather than promising one universal code path.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
If your program must support both sessions, detect the environment, keep an X11 backend for X11, and make the Wayland portal backend a separate module. Report a clear error when no permitted capture source is available.
Rank #2
- [Enhanced 4K-1080P Video Capture Experience] Capture the Magic: Elevate your video recordings to new heights with our upgraded anti-static 1080P Video Capture Card. Immerse yourself in stunning visuals, supporting HDMI input at 4K 60FPS and USB output for capturing in 1080P, complete with rich stereo sound. Enjoy crystal-clear video recordings, dynamic gaming live streams, and professional conference broadcasts. Note: HDMI resolution: Max input can be 3840×2160@30Hz / Video output resolution: Max output can be 1920×1080@30Hz
- [Seamless Real-Time Preview] Stay in the Moment: Our advanced ultra-low latency technology ensures seamless real-time transmission of video streams. Experience instant, lag-free previews, allowing you to capture every detail precisely. Effortlessly record video directly to your hard disk, all without compromising on quality or introducing any delays.
- [Versatility and Broad Compatibility] Your Creative Hub: Connect your DSLR, camcorder, or action camera to a wide range of operating systems, including Windows, MacOS, and Linux. Unlock a world of possibilities with real-time streaming to popular platforms like Twitch, Youtube, OBS, Zoom, Potplayer, and VLC, giving you the tools to share your content effortlessly.
- [Effortless Plug and Play] Simplicity Redefined: Say goodbye to complex installations. Our plug-and-play design eliminates the need for drivers or external power supplies. Seamlessly integrate high-definition acquisition into various scenarios, whether it's educational recordings, immersive gaming, precise medical imaging, captivating live streams, or professional broadcasting.
- [Seize Every Detail with Precision] Unleash your creativity and attention to detail with our video capture card. Capture every nuance, every color, and every moment with precision, thanks to the enhanced capabilities of our technology. Whether you're a content creator, a gamer, or a professional, our capture card empowers you to seize the finest elements and bring them to life in your recordings and live streams.
Windows: select the least complex API that fits
Windows.Graphics.Capture for a user-selected still
Windows.Graphics.Capture invokes system UI so the user selects an application window or display. The normal flow is: create a capture item, create a capture session, receive a frame, copy the frame into an image buffer, and encode one image. Microsoft documents this workflow and an example that saves an image; that example is in C#, so a C implementation must use the Windows SDK’s ABI interfaces or a supported language projection and verify the declarations against its target SDK.
Check that the API is supported on the Windows desktop device (and, where relevant, Windows Mixed Reality headset) before exposing the control. A picker-driven design is preferable when users must explicitly choose what is shared.
Win32 GDI for a basic bitmap
For older or straightforward Win32 applications, the documented “Capturing an Image” pattern creates a compatible device context, creates and selects a compatible bitmap, copies pixels into it and saves a BMP. Keep the device contexts and bitmap lifetimes explicit: select the original object back before deleting a context, release the screen device context, and close the file even on error. GDI is suitable for a single bitmap but does not provide the modern consent and frame-management model of Windows.Graphics.Capture.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchDXGI Desktop Duplication for continuous capture
Use DXGI Desktop Duplication when you need a stream of desktop frames, such as collaboration or recording. Each call to AcquireNextFrame supplies a BGRA surface plus metadata for dirty rectangles, moved rectangles and pointer position. A robust loop must:
- release every acquired frame and its resources;
- handle timeouts and duplication loss by recreating the duplication interface;
- apply dirty and moved regions rather than assuming the entire surface changed;
- rotate the image for rotated display modes; and
- draw the pointer when the cursor is supplied separately from the surface.
That bookkeeping makes Desktop Duplication substantially more involved than a one-off screenshot.
Rank #3
- 【4K HDMI Input, 2K@30Hz Recording】Powered by a true USB 3.0 high-speed interface, the capture card supports up to 4K@30Hz HDMI input and records at 2K@30Hz or 1080P@60Hz. Perfect for gamers, streamers, and professionals who need crisp, smooth video for live streaming, gameplay recording, or online meetings.
- 【Ultra Low Latency Screen Sharing】Built with a premium aluminum alloy shell and advanced chipset for stable heat dissipation, ensuring ultra-low latency transmission. Capture high-quality video and dual-channel audio in real time—no lag, no frame drop—ideal for Twitch, YouTube, or OBS streaming.
- 【Easy Plug and Play, Compact & Portable】No driver or external power required—just plug and play via USB 3.0 or Type-C connection to your Windows or macOS computer. Lightweight and compact design makes it easy to carry for outdoor streaming, live shows, or mobile recording setups.
- 【Wide Compatibility & Multi-Device Support】Compatible with Windows 7 8 10 11, macOS, Linux,Android and supports most popular software such as OBS, Zoom, VLC, Twitch Studio, and more. Works seamlessly with PS4, PS5, Xbox, Switch, DSLR cameras, TV boxes, and other HDMI-output devices for streaming to YouTube, Twitch, etc.
- 【What You Get】Includes: HDMI Capture Card, USB 3.0 to USB-C Adapter, User Manual. Tips: Make sure your tablet’s OTG function is enabled before connecting. Test your HDMI device with a monitor first to confirm video and audio output, then connect to the Video Capture Card for recording.
macOS: ScreenCaptureKit with a permission-aware bridge
Apple’s current documented route is ScreenCaptureKit. It represents shareable displays, applications and windows; SCScreenshotManager handles a single frame, while SCStream handles ongoing media capture. Apple recommends the system content-sharing picker for source selection.
Before capture, the user must grant Screen Recording permission. Your application should explain why it needs access and direct the user to the macOS privacy settings when permission is absent. ScreenCaptureKit’s interfaces and Apple sample code are Objective-C/Swift oriented. A program whose core is C therefore needs an Objective-C interoperability layer (for example, an Objective-C source file exposing a C-callable wrapper), rather than pretending the framework is an ISO C library.
Do not copy sample prerequisites into a universal version claim: Apple’s current capture sample states macOS 15 or later and Xcode 16 or later, while the minimum supported version for a particular ScreenCaptureKit feature must be checked in the SDK documentation you build against.
QNX: a privileged embedded path
QNX uses its Screen API to copy display or window pixels into an appropriately configured pixmap or window buffer. The official tutorial requires a display-capture context with a privileged display-manager context and an effective user ID of root. That is an embedded QNX requirement, not a Linux desktop workaround. Keep QNX code and deployment policy in a dedicated backend, and fail safely when the process lacks the required privilege.
Encoding, color and memory considerations
- Pixel order: APIs commonly return BGRA, BGRX or packed visual formats. Inspect the documented format and channel masks before writing bytes.
- Stride: A row’s byte count may exceed width × bytes-per-pixel. Iterate by the supplied stride, not by a guessed tightly packed size.
- Coordinate systems: Multi-monitor arrangements can include negative coordinates and different scale factors. Store coordinates in the API’s coordinate space and document whether output is logical or physical pixels.
- Large displays: A 4K RGBA frame is roughly 33 MB before encoder overhead. Avoid unnecessary copies and release frame surfaces promptly.
- Output format: PNG preserves text and transparency; JPEG is smaller but lossy; WebP may reduce size further when your deployment can decode it. A BMP or PPM writer is useful for diagnostics, not necessarily for delivery.
- Security: Screenshots can contain passwords, tokens and personal data. Restrict file permissions, avoid accidental logging of image bytes, and delete temporary files according to your application’s policy.
Troubleshooting common failures
“There is no display” or the connection is denied
On X11, check DISPLAY and the X server’s authorization. In a service or SSH session, there may be no interactive display at all. On Wayland, use the portal rather than setting an X11 variable and hoping it grants access.
Rank #4
- 【1080P HD High Quality】Capture resolution up to 1080p for video source and it is ideal for all HDMI devices such as PS4, PS3, Xbox One, Xbox 360, Wii U, DVDs, DSLR, Camera, Security Camera and set top box. Note: Video input supports 4K30/60Hz and 1080p120/144Hz. Does not support 4K120Hz/144Hz. Output supports up to 2K30Hz.
- 【Plug and Play】No driver or external power supply required, true PnP. Once plugged in, the device is identified automatically as a webcam. Detect input and adjust output automatically. Won't occupy CPU, optional audio capture. No freeze with correct setting.
- 【Compatible with Multiple Systems】suitable for Windows and Mac OS. High speed USB 3.0 technology and superior low latency technology makes it easier for you to transmit live streaming to Twitch, Youtube, Facebook, Twitter, OBS, Potplayer and VLC.
- 【HDMI LOOP-OUT】Based on the high-speed USB 3.0 technology, it can capture one single channel HD HDMI video signal. There is no delay when you are playing game live.
- 【Support Mic-in for Commentary】Rybozen capture card has microphone input and you can use it to add external commentary when playing a game. Please note: it only accepts 3.5mm TRS standard microphone headset.
The image is black, blank or incomplete
Verify that the capture permission was granted, the selected source still exists, and your frame is synchronized before copying it. For DXGI, handle duplication loss and rotation. For X11, confirm that the root window and visual masks match the conversion code.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →macOS reports missing permission
Open the system Privacy & Security settings, enable Screen Recording for the application, then restart it if macOS requires a new authorization session. Do not silently retry forever; show the user the exact permission state.
Colors are wrong
Inspect channel order, bit masks, alpha semantics and row stride. BGRA interpreted as RGBA produces swapped red and blue channels; a mask-based conversion is safer than fixed shifts.
Capture works once but leaks memory or hangs
Use one cleanup path for every API object, release acquired frames in all branches, and bound waits with timeouts. Continuous capture should process or drop frames deliberately instead of allowing an unbounded queue.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
If your goal is a clean image of a web page rather than pixels from the user’s desktop, ScreenshotNeo is a simpler API option. It accepts a URL and returns PNG, JPEG, WebP or PDF. Before capture it accepts cookie/consent banners and removes more than 60 known consent platforms, newsletter popups and chat widgets. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed; response headers identify the page verdict and billing result. Its MCP server provides take_screenshot, get_page_info and capture_pdf tools for Claude, Cursor and other MCP clients.
Free tools Windows power users keep installed
One-click scans. No signup required.
One call from C or any shell can save a screenshot:
Best Value
- AV TO USB Converter: Capture videos and audios from VHS, VCR, Hi8, DV tapes to a PC, with the help of our USB Video Converter. Save room while digitizing your favorite old memories
- Quality Capture Card: Our USB Video Capture Card converting anolog RCA composite input into HD 720P USB output and capturing audio without any sound card. Advanced signal processing technology provides you with great precision, colors, resolutions, and details.
- Plug and Play: Automatically install the driver once you hook up this RCA to USB Converter to a PC. No external power is needed. User-friendly and easy to operate
- Wide Compatibility: The Video Capture Card can work with video devices with RCA connector or S-Video connector, such as VHS, VCR, Hi8, camcorder, compatible with Windows and Mac OS. Support video formats like NTSC, PAL, and support brightness, contrast, hue, and saturation control
- Note: The Video Converter is used with acquisition software. We recommend OBS Studio or PotPlayer for Windows, and QuickTime Player for Mac. They can be downloaded for free online. Please operate according to the steps in User Manual or contact us if you have any questions
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo documentation for authentication, capture options and response headers. The service also supports full-page and element captures, dark mode, device presets, retina scale, custom CSS and JavaScript, clicks, waits, request blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed links, asynchronous webhooks, bulk capture of up to 100 URLs per call, a usage API and an OpenAPI specification.
There is a free allowance of 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is included on every plan. Create a free ScreenshotNeo account.
FAQ
Can standard C take a screenshot without operating-system APIs?
No. ISO C has no display or screenshot interface; use a platform backend or a service that captures the web content for you.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsIs a screenshot the same as a desktop video frame?
No. A still capture can be a single image, while DXGI Desktop Duplication and ScreenCaptureKit streams require frame timing, resource management and recovery logic.
Why does an X11 example fail under Wayland?
Wayland restricts direct screen reads and normally requires a portal or compositor-approved workflow, so an X11 root-window call is not a portable Linux solution.
Frequently Asked Questions
Can standard C take a screenshot without operating-system APIs?
No. ISO C has no display or screenshot interface; use a platform backend or a service that captures the web content for you.
Is a screenshot the same as a desktop video frame?
No. A still capture can be a single image, while DXGI Desktop Duplication and ScreenCaptureKit streams require frame timing, resource management and recovery logic.
Recommended Free Tools
Why does an X11 example fail under Wayland?
Wayland restricts direct screen reads and normally requires a portal or compositor-approved workflow, so an X11 root-window call is not a portable Linux solution.
Quick Recap
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.




