Skip to content

ui::ImageDiff

Header: winui/render/Bitmap.hpp.

Comparison result for golden-image tests, from compare().

Example:

// A screen-capture tool that keeps a new capture only when it differs from the last one.
void keep_if_changed(const ui::Bitmap& capture, ui::Bitmap& last_capture, int& capture_index)
{
    const ui::ImageDiff diff = ui::compare(capture, last_capture, 2); // ignore differences up to 2
    if (!diff.same_size || diff.mismatched_pixels > 0)
    {
        capture.write_png(std::format("capture-{}.png", ++capture_index));
        last_capture = capture;
    }
}

Field Type Default
same_size bool false False when the dimensions differ (nothing else is compared).
max_channel_delta int 0 Largest absolute per-channel difference, 0..255.
mismatched_pixels std::size_t 0 Pixels differing by more than the threshold.
total_pixels std::size_t 0 Pixels compared.