private void testDraw() { CadSize2D deviceSize = new CadSize2D(827, 1169); CadSize2D pageSize = new CadSize2D(210, 297); DrawContext dc = Controller.DC.CreatePrinterContext(pageSize, deviceSize); dc.SetupTools(DrawTools.DrawMode.PRINTER); FrameBufferW fb = new FrameBufferW(); fb.Create((int)deviceSize.Width, (int)deviceSize.Height); fb.Begin(); dc.StartDraw(); dc.Drawing.Clear(dc.GetBrush(DrawTools.BRUSH_BACKGROUND)); Controller.DrawFiguresRaw(dc); dc.EndDraw(); Bitmap bmp = fb.GetBitmap(); fb.End(); fb.Dispose(); bmp.Save(@"F:\work\test2.bmp"); }
private static Bitmap GetPrintableBmp(PlotterController pc, CadSize2D pageSize, CadSize2D deviceSize) { if (!(pc.DC is DrawContextGL)) { return(null); } DrawContext dc = pc.DC.CreatePrinterContext(pageSize, deviceSize); dc.SetupTools(DrawTools.DrawMode.PRINTER); // Bitmapを印刷すると大きさが変わるので、補正 double f = SettingsHolder.Settings.MagnificationBitmapPrinting; dc.UnitPerMilli *= f; //dc.UnitPerMilli *= 0.96; Vector3d org = dc.ViewOrg; //org *= 0.96; org *= f; dc.SetViewOrg(org); FrameBufferW fb = new FrameBufferW(); fb.Create((int)deviceSize.Width, (int)deviceSize.Height); fb.Begin(); dc.StartDraw(); GL.Disable(EnableCap.LineSmooth); dc.Drawing.Clear(dc.GetBrush(DrawTools.BRUSH_BACKGROUND)); pc.DrawFiguresRaw(dc); GL.Enable(EnableCap.LineSmooth); dc.EndDraw(); Bitmap bmp = fb.GetBitmap(); fb.End(); fb.Dispose(); return(bmp); }
public void Clear(DrawContext dc = null) { dc.Drawing.Clear(dc.GetBrush(DrawTools.BRUSH_BACKGROUND)); }
protected void DrawFigures(DrawContext dc) { if (dc == null) { return; } DrawParams pale_dp = default; DrawParams test_dp = default; DrawParams current_dp = default; DrawParams measure_dp = default; DrawParams empty_dp = default; empty_dp.Empty = true; pale_dp.LinePen = dc.GetPen(DrawTools.PEN_PALE_FIGURE); pale_dp.EdgePen = dc.GetPen(DrawTools.PEN_PALE_FIGURE); pale_dp.FillBrush = DrawBrush.NullBrush; pale_dp.TextBrush = dc.GetBrush(DrawTools.BRUSH_PALE_TEXT); test_dp.LinePen = dc.GetPen(DrawTools.PEN_TEST_FIGURE); test_dp.EdgePen = dc.GetPen(DrawTools.PEN_TEST_FIGURE); test_dp.FillBrush = DrawBrush.NullBrush; test_dp.TextBrush = dc.GetBrush(DrawTools.BRUSH_TEXT); current_dp.LinePen = dc.GetPen(DrawTools.PEN_FIGURE_HIGHLIGHT); current_dp.EdgePen = dc.GetPen(DrawTools.PEN_FIGURE_HIGHLIGHT); current_dp.FillBrush = DrawBrush.NullBrush; current_dp.TextBrush = dc.GetBrush(DrawTools.BRUSH_TEXT); measure_dp.LinePen = dc.GetPen(DrawTools.PEN_MEASURE_FIGURE); measure_dp.EdgePen = dc.GetPen(DrawTools.PEN_MEASURE_FIGURE); measure_dp.FillBrush = DrawBrush.NullBrush; measure_dp.TextBrush = dc.GetBrush(DrawTools.BRUSH_TEXT); AlphaFigList.Clear(); AlphaFigListCurrentLayer.Clear(); lock (DB) { foreach (CadLayer layer in mDB.LayerList) { if (!layer.Visible) { continue; } // Skip current layer. // It will be drawn at the end of this loop. if (layer == CurrentLayer) { continue; } foreach (CadFigure fig in layer.FigureList) { if (fig.Type == CadFigure.Types.DIMENTION_LINE) { AlphaFigList.Add(fig); continue; } if (fig.Current) { fig.DrawEach(dc, current_dp); } else { fig.DrawEach(dc, pale_dp); } } } // Draw current layer at last if (CurrentLayer != null && CurrentLayer.Visible) { foreach (CadFigure fig in CurrentLayer.FigureList) { if (fig.Type == CadFigure.Types.DIMENTION_LINE) { AlphaFigListCurrentLayer.Add(fig); continue; } if (fig.Current) { fig.DrawEach(dc, current_dp); } else { fig.DrawEach(dc); } } } foreach (CadFigure fig in TempFigureList) { if (fig.Type == CadFigure.Types.DIMENTION_LINE) { continue; } fig.DrawEach(dc, test_dp); } if (MeasureFigureCreator != null) { if (MeasureFigureCreator.Figure.Type != CadFigure.Types.DIMENTION_LINE) { MeasureFigureCreator.Figure.Draw(dc, measure_dp); } } // Alpha指定があるFigureを描画 foreach (CadFigure fig in AlphaFigList) { if (fig.Current) { fig.DrawEach(dc, current_dp); } else { fig.DrawEach(dc, pale_dp); } } foreach (CadFigure fig in AlphaFigListCurrentLayer) { if (fig.Current) { fig.DrawEach(dc, current_dp); } else { fig.DrawEach(dc); } } foreach (CadFigure fig in TempFigureList) { if (fig.Type != CadFigure.Types.DIMENTION_LINE) { continue; } fig.DrawEach(dc, test_dp); } if (MeasureFigureCreator != null) { if (MeasureFigureCreator.Figure.Type == CadFigure.Types.DIMENTION_LINE) { MeasureFigureCreator.Figure.Draw(dc, measure_dp); } } } }
public void CreateBitmap(int w, int h, uint argb, int lineW, string fname) { DrawContext dc = Controller.DC; CadObjectDB db = Controller.DB; List <uint> idlist = Controller.DB.GetSelectedFigIDList(); var figList = new List <CadFigure>(); idlist.ForEach(id => { figList.Add(db.GetFigure(id)); }); CadRect r = CadUtil.GetContainsRectScrn(dc, figList); CadRect wr = default(CadRect); wr.p0 = dc.DevPointToWorldPoint(r.p0); wr.p1 = dc.DevPointToWorldPoint(r.p1); DrawContextGDIBmp tdc = new DrawContextGDIBmp(); tdc.WorldScale = dc.WorldScale; tdc.SetCamera(dc.Eye, dc.LookAt, dc.UpVector); tdc.CalcProjectionMatrix(); tdc.SetViewSize(w, h); tdc.SetViewOrg(new Vector3d(w / 2, h / 2, 0)); tdc.SetupTools(DrawTools.DrawMode.DARK); Pen pen = new Pen(Color.FromArgb((int)argb), lineW); DrawPen drawPen = new DrawPen(pen); double sw = r.p1.X - r.p0.X; double sh = r.p1.Y - r.p0.Y; double a = Math.Min(w, h) / (Math.Max(sw, sh) + lineW); tdc.DeviceScaleX *= a; tdc.DeviceScaleY *= a; CadRect tr = CadUtil.GetContainsRectScrn(tdc, figList); Vector3d trcp = (Vector3d)((tr.p1 - tr.p0) / 2 + tr.p0); Vector3d d = trcp - tdc.ViewOrg; tdc.SetViewOrg(tdc.ViewOrg - d); DrawParams dp = default; dp.LinePen = drawPen; dp.EdgePen = drawPen; Env.RunOnMainThread((Action)(() => { tdc.Drawing.Clear(dc.GetBrush(DrawTools.BRUSH_TRANSPARENT)); tdc.GdiGraphics.SmoothingMode = SmoothingMode.AntiAlias; foreach (CadFigure fig in figList) { fig.Draw(tdc, dp); } if (fname.Length > 0) { tdc.Image.Save(fname); } else { BitmapUtil.BitmapToClipboardAsPNG(tdc.Image); } tdc.Dispose(); drawPen.Dispose(); })); }