VectorDraw常見問題整理:如何像插入塊對話框中那樣獲得vdBlock的圖像預覽?

   VectorDraw Developer Framework(VDF)是一個用於應用程序可視化的圖形引擎庫。有了VDF提供的功能,您可以輕鬆地創建、編輯、管理、輸出、輸入和打印2D和3D圖形文件。   


 問:

    我如何像插入塊對話框中那樣獲得vdBlock的圖像預覽?

答:

    vdBlocks內部不包含它們的預覽,因此您需要使用vdRender快速創建一個。

    在表單中添加一個vdFramed / vdScrollable / vdBase控件,一個按鈕和一個圖片框,打開一個圖形並嘗試如下代碼:

     private void button1_Click(object sender, EventArgs e)
        {
            doc = vdFramedControl1.BaseControl.ActiveDocument;

            vdBlock blk = doc.Blocks.FindName("VDDIM_DEFAULT"); // try here some block names that exist in the drawing you opened
            if (blk == null) return; // block not found 
            // imgblock is a picturebox  private System.Windows.Forms.PictureBox imgblock; added to the form

            int blockwid = imgblock.Width;
            int blockhei = imgblock.Height;
            Bitmap image = new Bitmap(blockwid, blockhei);
            VectorDraw.Render.vdRender rend = new VectorDraw.Render.GDIPlusRender(null);
            rend.graphics = Graphics.FromImage(image);
            rend.UpperLeft = new Point(0, 0);
            rend.Width = blockwid;
            rend.Height = blockhei;
            rend.ViewSize = blockhei;
            rend.ViewCenter = new VectorDraw.Geometry.gPoint((double)rend.Width / 2.0d, (double)rend.Height / 2.0d);
            rend.Init();
            rend.StartDraw(false);
            rend.Clear(doc.Palette.Background);
            VectorDraw.Render.vdGdiPenStyle ps = new VectorDraw.Render.vdGdiPenStyle();
            ps.LineType = doc.LineTypes.Solid.GetgrLineType();
            ps.color = Color.Black;
            rend.PushPenstyle(ps);

            vdInsert ins = new vdInsert();
            ins.SetUnRegisterDocument(doc);
            ins.setDocumentDefaults();
            ins.Block = blk;
            double hei = ins.BoundingBox.Height;
            double wid = ins.BoundingBox.Width;
            double max = Math.Max(hei, wid);
            double min = Math.Min(hei, wid);
            ins.InsertionPoint = new VectorDraw.Geometry.gPoint(0.0d, 0.0d, 0.0d);
            rend.ViewSize = max * 5.0 / 4.0;
            rend.ViewCenter = new VectorDraw.Geometry.gPoint(ins.BoundingBox.MidPoint);
            ins.Update();
            ins.Draw(rend);

            rend.PopPenstyle();
            rend.EndDraw();
            rend.graphics.Dispose();
            rend.graphics = null;
            imgblock.Image = image;

        }

    對於以上問答,如果您有任何的疑惑都可以在評論區留言,我們會及時回覆。此係列的問答教程我們會持續更新,如果您感興趣,可以多多關注本教程。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章