private void PrintToChart() { lock (_drawLocker) { Dispatcher.Invoke(new Action(() => { int width = (int)chart.ActualWidth; int height = (int)chart.ActualHeight; wBitmap = new WriteableBitmap(width, height, 72, 72, PixelFormats.Bgr24, null); wBitmap.Lock(); Bitmap backBitmap = new Bitmap(width, height, wBitmap.BackBufferStride, System.Drawing.Imaging.PixelFormat.Format24bppRgb, wBitmap.BackBuffer); Graphics graphics = Graphics.FromImage(backBitmap); graphics.Clear(System.Drawing.Color.White);//整张画布置为白色 //-----------------------画图内容-------------------------start System.Drawing.Image image = graphEdit.GetCurrentGraph(this.GetBaseData(), XRange, YRange, false); //如果是面积曲线图将最后一个参数设为true graphics.DrawImage(image, 0, 0); //-----------------------画图内容-------------------------end graphics.Flush(); graphics.Dispose(); graphics = null; backBitmap.Dispose(); backBitmap = null; wBitmap.AddDirtyRect(new Int32Rect(0, 0, width, height)); wBitmap.Unlock(); DisplayImage.Source = wBitmap; })); } }
public void DrawCurve() { Init(); _Image = graphEdit.GetCurrentGraph(this.GetBaseData(), XRange, YRange, false); //如果是面积曲线图将最后一个参数设为true this.InvalidateVisual(); }