Why do I get weird artifacts in the alpha-channel of my rendered image?

Explanation

On Windows, most of the platform-specific widgets (buttons, scrollbars, etc.) are rendered directly using GDI. The problem is that GDI has very limited support for transparency (it largely ignores the alpha-channel) which explains the strange artifacts in the alpha-channel of the buffer.

Solution

This problem should only manifest itself on Windows.

If you are alpha-blending your image or need to write the image to a format that supports transparency, it is recommended to clear all of the alpha-bits of the buffer yourself after each call to WebView::render (e.g., set every fourth byte of the buffer to 255).

Here's an example:

const Awesomium::RenderBuffer* renderBuffer = myWebView->render();

unsigned char* buffer = renderBuffer->buffer;
int width = renderBuffer->width;
int height = renderBuffer->height;

// Set every 4th pixel-component (the 'A' of BGRA) to 255
for(int i = 0; i < width * height * 4; i += 4)
    buffer[i + 3] = 255;