Hi guys!
I'm using the following code to take a snapshot of the model:
private Bitmap GetScreenshot() { int cvPort = Convert.ToInt32(Application.GetSystemVariable(RenderingManager.CVPORT_SYS_VAR)); using (View view = new View()) { this.graphicsManager.SetViewFromViewport(view, cvPort); view.VisualStyle = new VisualStyle(VisualStyleType.Hidden); using (Device dev = this.graphicsManager.CreateAutoCADOffScreenDevice()) { dev.OnSize(graphicsManager.DisplaySize); dev.DeviceRenderType = RendererType.Default; dev.BackgroundColor = System.Drawing.Color.White; dev.Add(view); dev.Update(); using (Model model = graphicsManager.CreateAutoCADModel()) { using (Transaction transaction = this.database.TransactionManager.StartTransaction()) { BlockTable blockTable = (BlockTable)transaction.GetObject(this.database.BlockTableId, OpenMode.ForRead); BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForRead); view.Add(blockTableRecord, model); transaction.Commit(); } Bitmap bitmap = view.GetSnapshot(view.Viewport); view.EraseAll(); dev.Erase(view); return bitmap; } } } }
I'm currently passing the entire viewport to the GetSnapshot method, but I'd like to restrict it to the minumun rectangle containing the drawing. The following image explains what I mean (in red the viewport, in black what i need):
how can I compute the black rectangle? Thanks in advance for any answer!
You can select all the entitys in the drawing and then you can get the
GeometricExtents of each entity. This you can combine to the Bounding Box of the drawing.
In fact the Extents3d class can manage that for you.
Extents3d ext = new Extents3d;
for each entity in drawing // here you need an editor.SeletAll() to obtain them
ext.AddExtents(entity.GeometricExtents);
After that ext will contain the bounding box of your drawing in world coordinates.
Ok! I'll try this!...Once I get the extents in this way, I have to convert them from WCS to DCS before passing them to GetSnapshot, right?