VDF常見(jiàn)問(wèn)題整理(二十四):如何像插入塊對(duì)話(huà)框中那樣獲得vdBlock的圖像預(yù)覽?
VectorDraw Developer Framework(VDF)是一個(gè)用于應(yīng)用程序可視化的圖形引擎庫(kù)。有了VDF提供的功能,您可以輕松地創(chuàng)建、編輯、管理、輸出、輸入和打印2D和3D圖形文件。
VectorDraw Developer Framework試用版下載
點(diǎn)開(kāi)本篇文章,是否對(duì)矢量圖形工具感興趣呢?來(lái)看看最新的矢量圖形工具測(cè)評(píng)吧!點(diǎn)擊此處>>即可直達(dá)哦!
問(wèn):
我如何像插入塊對(duì)話(huà)框中那樣獲得vdBlock的圖像預(yù)覽?
答:
vdBlocks內(nèi)部不包含它們的預(yù)覽,因此您需要使用vdRender快速創(chuàng)建一個(gè)。
在表單中添加一個(gè)vdFramed / vdScrollable / vdBase控件,一個(gè)按鈕和一個(gè)圖片框,打開(kāi)一個(gè)圖形并嘗試如下代碼:
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; }
對(duì)于以上問(wèn)答,如果您有任何的疑惑都可以在評(píng)論區(qū)留言,我們會(huì)及時(shí)回復(fù)。此系列的問(wèn)答教程我們會(huì)持續(xù)更新,如果您感興趣,可以多多關(guān)注本教程。
相關(guān)資料推薦:
點(diǎn)擊此處還有VectorDraw Developer Framework的demo示例等著你來(lái)體驗(yàn)哦!
如果您對(duì)想要購(gòu)買(mǎi)正版授權(quán)VectorDraw Developer Framework(VDF),可以聯(lián)系在線客服>>咨詢(xún)相關(guān)問(wèn)題。
關(guān)注慧聚IT微信公眾號(hào) ???,了解產(chǎn)品的最新動(dòng)態(tài)及最新資訊。