VDF常见问题整理(十三):透明度如何在VDF中运行?
VectorDraw Developer Framework(VDF)是一个用于应用程序可视化的图形引擎库。有了VDF提供的功能,您可以轻松地创建、编辑、管理、输出、输入和打印2D和3D图形文件。
VectorDraw Developer Framework试用版下载
问:
透明度如何在VDF中发挥作用?
答:
在版本6023中,我们为vdFigure对象添加了一个名为TransparencyMethod的新属性。此属性从vdFigure.TransparencyMethodEnum获取值,如下所示:
TransparencyMethodEnum.ByLayer | 该对象采用透明度(AlphaBlending值)的颜色为图层pencolor AlphaBlending。 |
TransparencyMethodEnum.ByBlock | 该对象获取所有者的颜色透明度(AlphaBlending值)。所有者是一个带有AlphaBlending笔颜的vdInsert。 |
TransparencyMethodEnum.Default默认值 | 如果对象是真彩色,则对象将获得自己的透明度值。如果笔触是索引,则使用调色板的颜色透明度值。 |
TransparencyMethodEnum.KeepOwn | 该对象总是采用它自己的pencolor透明度(AlphaBlending值)。 |
除此属性外,还有Solid2dTransparency属性,该属性仅应用于阴影线/填充对象,并且仅应用于2D(线)模式,而不应用于3D(Wire3d / Shade / Hide / ShadeOn / Render)模式。因此,如果您希望填充的对象仅在2D而不是3D中透明,则可以使用此属性。
另一方面,如果您希望对象在3D和2D模式下透明,则需要使用TransparencyMethod属性并将AlphaBlending值设置为vdFigure (KeepOwn,Default)或vdLayer(ByLayer)或parent(vdBlock)。AlphaBlending将值从0(完全透明,如不可见)取值到255(根本不透明)。
本方法适用于版本6.6023.x及更高版本,因为以前的6023版本中不存在用于vdFigure的TransparencyMethod。
下面的代码将向您演示对象的透明度如何在VDF中工作:
public partial class Form1 : Form { public Form1() { InitializeComponent(); } vdDocument doc; private void Form1_Load(object sender, EventArgs e) { doc = vdFramedControl1.BaseControl.ActiveDocument; } private void button1_Click(object sender, EventArgs e) { //Transparency of vdCurves (line, polyline etc). // For better display of this transparency a thicker line type is used in the code doc.New(); vdRect rect = new vdRect(doc, new gPoint(0, 0, -0.1), 10, 2, 0); rect.HatchProperties = new vdHatchProperties(VdConstFill.VdFillModeSolid); doc.Model.Entities.AddItem(rect); // this is added just for better transparency display // Using the transparency in the object by setting the AlphaBlending vdCircle cir1 = new vdCircle(doc, new gPoint(2, 2), 1.0d); cir1.LineWeight = VdConstLineWeight.LW_211; cir1.PenColor.ColorIndex = 2; cir1.PenColor.AlphaBlending = 120; // the PenColor.AlphaBlending will be applied cir1.TransparencyMethod = vdFigure.TransparencyMethodEnum.KeepOwn; doc.Model.Entities.AddItem(cir1); // Using the transparency in the Layer vdLayer lay = new vdLayer(doc, "Transparent"); lay.PenColor.FromSystemColor(Color.Red); // layer is red !!! lay.PenColor.AlphaBlending = 120; // setting layer's transparency doc.Layers.AddItem(lay); vdCircle cir2 = new vdCircle(doc, new gPoint(4.7, 2), 1.2d); cir2.LineWeight = VdConstLineWeight.LW_200; cir2.Layer = lay; cir2.PenColor.ColorIndex = 2; // but object is not colored by layer, only transparency is by layer here // Layer's alpha blending wil be applied cir2.TransparencyMethod = vdFigure.TransparencyMethodEnum.ByLayer; doc.Model.Entities.AddItem(cir2); // Using the transparency inside blocks/inserts vdBlock blk = new vdBlock(doc, "Transparecy"); vdCircle cir3 = new vdCircle(doc, new gPoint(8, 2, 0), 1.5); // bigger circle cir3.PenColor.ColorIndex = 2; cir3.LineWeight = VdConstLineWeight.LW_158; // the insert's Aplha blending will be applied cir3.TransparencyMethod = vdFigure.TransparencyMethodEnum.ByBlock; blk.Entities.AddItem(cir3); cir3 = new vdCircle(doc, new gPoint(8, 2, 0), 0.7); //smaller circle cir3.PenColor.ByBlock = true; cir3.LineWeight = VdConstLineWeight.LW_158; // the layer's Aplha blending will be applied which isn't transparent cir3.TransparencyMethod = vdFigure.TransparencyMethodEnum.ByLayer; blk.Entities.AddItem(cir3); doc.Blocks.AddItem(blk); vdInsert ins = new vdInsert(doc, blk, new gPoint(0, 0, 0), 0, 1, 1, 1); // setting the inserts draw to use the Alpha Blending ins.TransparencyMethod = vdFigure.TransparencyMethodEnum.Default; ins.PenColor.FromSystemColor(Color.Yellow); ins.PenColor.AlphaBlending = 120; // setting transparency to 120 doc.Model.Entities.AddItem(ins); doc.Model.ZoomExtents(); doc.Redraw(true); } private void button2_Click(object sender, EventArgs e) { // Hatches/Filled objects and Transparency doc.New(); vdRect rect = new vdRect(doc, new gPoint(0, 0, -0.1), 10, 2, 0); rect.HatchProperties = new vdHatchProperties(VdConstFill.VdFillModeSolid); doc.Model.Entities.AddItem(rect); // this is added just for better transparency display // 2D Transparency Does NOT work in 3D modes (hide/shade/render/wire3D) vdCircle cir1 = new vdCircle(doc, new gPoint(2, 2), 1.0d); cir1.HatchProperties = new vdHatchProperties(VdConstFill.VdFillModeSolid); cir1.HatchProperties.Solid2dTransparency = 80; // values 0 (invisible) to 255 (no transparency) cir1.PenColor.FromSystemColor(Color.Red); cir1.HatchProperties.FillColor.FromSystemColor(Color.Green); doc.Model.Entities.AddItem(cir1); // Transparency in PenColor work ALSO in 3D modes (hide/shade/render/wire3D) vdCircle cir2 = new vdCircle(doc, new gPoint(4.7, 2), 1.2d); cir2.HatchProperties = new vdHatchProperties(VdConstFill.VdFillModeSolid); cir2.PenColor.FromSystemColor(Color.Green); cir2.HatchProperties.FillColor.FromSystemColor(Color.Red); cir2.HatchProperties.FillColor.AlphaBlending = 80;// values 0 (invisible) to 255 (no transparency) doc.Model.Entities.AddItem(cir2); // the above modes can be compbined with TransparencyMethod of vdfigure (that work in 3D modes), like vdCircle cir3 = new vdCircle(doc, new gPoint(8, 2, 0), 1.5); cir3.PenColor.ColorIndex = 4; cir3.LineWeight = VdConstLineWeight.LW_200; cir3.PenColor.AlphaBlending = 80; cir3.HatchProperties = new vdHatchProperties(VdConstFill.VdFillModeSolid); cir3.HatchProperties.FillColor.FromSystemColor(Color.Green); cir3.HatchProperties.FillColor.AlphaBlending = 80; cir3.TransparencyMethod = vdFigure.TransparencyMethodEnum.KeepOwn; doc.Model.Entities.AddItem(cir3); doc.Model.ZoomExtents(); doc.Redraw(true); } }
相关资料推荐:
VectorDraw Developer Framework(VDF)示例