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;
}
对于以上问答,如果您有任何的疑惑都可以在评论区留言,我们会及时回复。此系列的问答教程我们会持续更新,如果您感兴趣,可以多多关注本教程。