You screenshot your code editor in dark mode, drop the image into an OCR tool, and get back... nothing. Or a scatter of punctuation marks. The text is perfectly readable to you — bright white letters on a near-black screen. To most OCR engines, though, the image is upside down in the one way that matters.
Almost every OCR pipeline assumes dark text on a light background, because that is what printed documents look like. White text on black breaks that assumption, and the fix is simple once you know it: invert the image first. This guide covers why dark backgrounds fail, how inversion fixes them, the exceptions where inversion is not enough, and a reliable step-by-step workflow.
Why dark backgrounds return empty results
Before recognising characters, an OCR engine usually converts the image to pure black and white — a step called binarisation. It picks a brightness threshold: pixels darker than the threshold become "ink," lighter pixels become "paper." On a normal page, letters are dark and paper is light, so this works.
On a dark-mode screenshot, the same logic misfires. Your white letters are the lightest thing in the image, so they get classified as paper. The black background becomes the "ink" — one giant blob with letter-shaped holes in it. The engine then looks for characters inside that blob, finds none, and returns an empty result or garbage. The text was never unreadable. It was just filed under the wrong category.
Some modern engines, including the Google Vision-based engine behind PictureText, detect inverted text automatically in many cases. But detection is inconsistent — it often works on pure black-and-white and fails on the coloured, mid-dark themes most apps actually use. When a dark screenshot comes back empty, do not assume the tool cannot read it. Prepare the image yourself.
The fix: invert the colours
Inversion (making a negative of the image) swaps every colour for its opposite: white text becomes black, the black background becomes white. The result looks like a normal printed page, which is exactly what the engine expects.
You can invert an image in almost any editor:
- Windows (Paint): open the image, select all (Ctrl+A), right-click and choose "Invert colors." Note newer Paint versions have moved this command around; if you cannot find it, use one of the options below.
- macOS (Preview): Preview has no one-click invert. Use Photos' edit sliders (push exposure and reverse contrast) or a free editor instead — the online options below are faster.
- Online editors: most free image editors (Photopea, Pixlr and similar) have Image → Adjustments → Invert. Upload, invert, download — thirty seconds.
- Phone: stock gallery editors on both iPhone and Android lack a true invert command. The practical option is a mobile web editor with an Invert adjustment in your browser, or sending the screenshot to a computer.
After inverting, run OCR again. On pure black-and-white material — terminal output, white-on-black slides, dark-mode documents with white body text — this single step usually takes the result from empty to clean.
When inversion is not enough: coloured text
Dark-mode code editors rarely use pure white text. Syntax highlighting adds blue keywords, green strings, orange numbers, purple functions. Inversion swaps these to their opposites but keeps them coloured, and some colours end up low-contrast against the new white background. Pale yellow text, for example, inverts to a dark blue that reads fine; the original pale yellow on dark grey reads badly in both directions after greyscale conversion because its brightness is close to the background's.
Handle coloured dark screenshots like this:
- Invert first. Always start here; it fixes the main text.
- Boost contrast. In your editor, raise contrast so faint colours separate from the background. Slight over-contrast is fine — you are feeding a machine, not framing a photo.
- If specific colours vanish, crop and process regions. A block of code where the green comments disappeared can be re-run on a tight crop; engines work harder on a small, uniform area. PictureText has a built-in crop tool, and the screenshot to text page is set up for exactly this kind of image.
- Consider re-screenshotting in a light theme. For code specifically, if you have access to the source application, switching the editor to a light theme for ten seconds and re-capturing beats every preprocessing trick in this article. It feels like cheating because it is — effective cheating.
Troubleshooting specific failures
Completely empty output. Classic binarisation failure. Invert and retry. If it is still empty, the image may be very low resolution — check the fixes in our OCR not working guide after inversion.
Main text fine, highlighted words missing. A colour issue, not an inversion issue. Apply the contrast step above, or crop the affected lines and run them separately.
Random punctuation in the output. Decorative elements — window borders, line-number gutters, scrollbar marks, syntax underlines — are being read as characters. Crop them out. In code screenshots, crop away the line numbers too; they insert stray digits into every line of output.
Text near a gradient or photo background. Slides with white text over a dark photo or gradient invert badly, because the background inverts to an uneven light mess. Crop to the text block so the crop is mostly uniform, invert, and increase contrast until the background flattens out.
A reliable workflow, start to finish
- Capture the screenshot at full size — do not shrink it.
- Open it in an editor and invert the colours.
- Raise contrast moderately; check that the faintest text you care about is clearly visible.
- Save as PNG (avoid re-saving as JPG, which adds artefacts around letter edges).
- Upload it to PictureText — you can paste from the clipboard, and images are processed in temporary memory and deleted right after processing, never stored or used to train AI.
- Scan the result for the known weak spots: coloured keywords, numbers in tables, and any line that sat next to an icon or border in the original.
Dark backgrounds are one of the easiest OCR problems to solve once you know the assumption the software is making. Invert, add contrast, crop the clutter — in that order — and most dark-mode text extracts cleanly.