VectorDraw Developer Framework(VDF)是一個用於應用程序可視化的圖形引擎庫。有了VDF提供的功能,您可以輕鬆地創建、編輯、管理、輸出、輸入和打印2D和3D圖形文件。
VectorDraw web library (javascript)不僅能打開CAD圖紙,而且能顯示任何支持HTML5標準平臺上的通用矢量對象,如Windows,安卓,iOS和Linux。無需任何安裝,VectorDraw web library (javascript)就可以運行在任何支持canvas標籤和Javascript的主流瀏覽器(Chrome, Firefox, Safari, Opera, Dolphin, Boat等等)中。這意味着可以用DXF,DWG,DGN,SKP(Google的Sketchup),VDML等多種格式在任何臺式、平板電腦,智能手機和便攜式筆記本上展現出你的業務。
問:
透明度如何在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); } }