private void InitializeGraphics(Database database) { try { var graphics = Graphics.FromHwnd(grpxView.Handle); // load some predefined rendering module (may be also "WinDirectX" or "WinOpenGL") using (var gsModule = (GsModule)SystemObjects.DynamicLinker.LoadModule("WinGDI_3.03_9.txv", false, true)) { // create graphics device using (var graphichsDevice = gsModule.CreateDevice()) { // setup device properties using (Dictionary props = graphichsDevice.Properties) { if (props.Contains("WindowHWND")) // Check if property is supported { props.AtPut("WindowHWND", new RxVariant((int)grpxView.Handle)); // hWnd necessary for DirectX device } if (props.Contains("WindowHDC")) // Check if property is supported { props.AtPut("WindowHDC", new RxVariant(graphics.GetHdc())); // hWindowDC necessary for Bitmap device } if (props.Contains("DoubleBufferEnabled")) // Check if property is supported { props.AtPut("DoubleBufferEnabled", new RxVariant(true)); } if (props.Contains("EnableSoftwareHLR")) // Check if property is supported { props.AtPut("EnableSoftwareHLR", new RxVariant(true)); } if (props.Contains("DiscardBackFaces")) // Check if property is supported { props.AtPut("DiscardBackFaces", new RxVariant(true)); } } // setup paperspace viewports or tiles ContextForDbDatabase ctx = new ContextForDbDatabase(database) { UseGsModel = true }; _helperDevice = LayoutHelperDevice.SetupActiveLayoutViews(graphichsDevice, ctx); //helperDevice.ActiveView.Mode = Teigha.GraphicsSystem.RenderMode.HiddenLine; } } // set palette _helperDevice.SetLogicalPalette(Device.DarkPalette); _helperDevice.Model.Invalidate(InvalidationHint.kInvalidateAll); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); } }
private void button1_Click(object sender, EventArgs e) { if (DialogResult.OK == openFileDialog.ShowDialog()) { using (GsModule gsModule = (GsModule)SystemObjects.DynamicLinker.LoadModule("WinDirectX.txv", false, true)) { // create graphics device using (Teigha.GraphicsSystem.Device dev = gsModule.CreateBitmapDevice()) { // setup device properties using (Dictionary props = dev.Properties) { props.AtPut("BitPerPixel", new RxVariant(int.Parse(comboBox1.Text))); } ContextForDbDatabase ctx = new ContextForDbDatabase(database); ctx.PaletteBackground = colorDialog.Color; LayoutHelperDevice helperDevice = LayoutHelperDevice.SetupActiveLayoutViews(dev, ctx); helperDevice.SetLogicalPalette(Device.LightPalette); // light palette Rectangle rect = new Rectangle(0, 0, (int)numericUpDownWidth.Value, (int)numericUpDownHeight.Value); helperDevice.OnSize(rect); ctx.SetPlotGeneration(checkBoxPlotGeneration.Checked); if (ctx.IsPlotGeneration) { helperDevice.BackgroundColor = colorDialog.Color; } else { helperDevice.BackgroundColor = Color.FromArgb(0, 173, 174, 173); } helperDevice.Update(); if (DialogResult.OK == saveFileDialog.ShowDialog()) { Export_Import.ExportBitmap(helperDevice, saveFileDialog.FileName); Close(); } } } } }