Code :
private void Foo(Canvas canvas)
{
// The content is a bit larger...
Size size = new Size(canvas.ActualWidth * 1.1, canvas.Act
Here's my last solution, hope it would help others with the same problem
// Create a render bitmap and push the surface to it
RenderTargetBitmap renderBitmap =
new RenderTargetBitmap(
(int)size.Width,
(int)size.Height,
96d,
96d,
PixelFormats.Pbgra32
);
renderBitmap.Render(surface);
// Create a white background render bitmap
int dWidth = (int)size.Width;
int dHeight = (int)size.Height;
int dStride = dWidth * 4;
byte[] pixels = new byte[dHeight * dStride];
for (int i = 0; i < pixels.Length; i++)
{
pixels[i] = 0xFF;
}
BitmapSource bg = BitmapSource.Create(
dWidth,
dHeight,
96,
96,
PixelFormats.Pbgra32,
null,
pixels,
dStride
);
// Adding those two render bitmap to the same drawing visual
DrawingVisual dv = new DrawingVisual();
DrawingContext dc = dv.RenderOpen();
dc.DrawImage(bg, new Rect(size));
dc.DrawImage(renderBitmap, new Rect(size));
dc.Close();
// Render the result
RenderTargetBitmap resultBitmap =
new RenderTargetBitmap(
(int)size.Width,
(int)size.Height,
96d,
96d,
PixelFormats.Pbgra32
);
resultBitmap.Render(dv);
// Copy it to clipboard
try
{
Clipboard.SetImage(resultBitmap);
} catch { ... }