I have a 3D render of WPF that I want to transfer to an Excel cell (via the clipboard).
With "normal" BMP images, this works, but I don't know how to convert a RenderTargetBitmap
.
My code is as follows:
System.Windows.Media.Imaging.RenderTargetBitmap renderTarget = myParent.GetViewPortAsImage(DiagramSizeX, DiagramSizeY); System.Windows.Controls.Image myImage = new System.Windows.Controls.Image(); myImage.Source = renderTarget; System.Drawing.Bitmap pg = new System.Drawing.Bitmap(DiagramSizeX, DiagramSizeY); System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(pg); gr.DrawImage(myImage, 0, 0); System.Windows.Forms.Clipboard.SetDataObject(pg, true); sheet.Paste(range);
My problem is that gr.DrawImage
does not accept System.Windows.Controls.Image
or System.Windows.Media.Imaging.RenderTargetBitmap
; only a System.Drawing.Image
.
How do I convert Controls.Image.Imaging.RenderTargetBitmap
to Image
, or are there any simpler ways?
source share