I'm trying to copy an image to the windows clipboard but windows keeps removing my alpha. This is may latest attempt where i manually create the buffer and copy the BGRA values to the buffer, however still when i read the values later alpha is set to 255. If i copy my image from Paint.NET I get an InteropBitmap
with the exact same values but alpha is set correct, so it should be possible. If i save my image to a PNG-file instead of the clipboard alpha is also correct.
var buffer = new byte[width * height * 4];
for (var x = 0; x < width; x++)
{
for (var y = 0; y < height; y++)
{
var pixel = surface[x, y];
var i = (y * width + x) * 4;
buffer[i + 0] = pixel.B;
buffer[i + 1] = pixel.G;
buffer[i + 2] = pixel.R;
buffer[i + 3] = pixel.A;
}
}
Clipboard.Clear();
Clipboard.SetImage(InteropBitmap.Create(
bounds.Width, bounds.Height,
96, 96,
PixelFormats.Bgra32,
null,
buffer,
width * 4));