2015-06-05 95 views

回答

0

使用RenderTargetBitmap對象的Render方法,有效地把你的畫布的捕獲作爲一個內存流 - 然後創建一個位圖:

var targetBitmap = new RenderTargetBitmap((int)yourCanvas.ActualWidth, (int)yourCanvas.ActualHeight, 96d, 96d, System.Windows.Media.PixelFormats.Default); 

targetBitmap.Render(yourCanvas); 

// add the RenderTargetBitmap to a Bitmap encoder 
var encoder = new BmpBitmapEncoder(); 
encoder.Frames.Add(BitmapFrame.Create(targetBitmap)); 

// create the memory stream 
var memoryStream = new MemoryStream(); 
encoder.Save(memoryStream); 

// create the bitmap 
var controlBitmap = new System.Drawing.Bitmap(memoryStream);