CAD .NET如何插入图片

作者:控件中国网   出处:控件中国网   2015-08-24 10:50:25   阅读:32

CAD .NET是一款CAD文件的浏览、编辑和转换控件,可以对CAD文件中的实体、层这些进行控制盒读取,同时也可以导入各种图片,下面的代码就是如何利用CAD .NET插入图片:

if (this.cadImage == null)
            {
                this.cadImage = new CADImage();
                this.cadImage.InitialNewImage();
            }
            this.cadImage.UseDoubleBuffering = false;

            CADLayer entLayer = new CADLayer();
            entLayer.Name = "MyLayer";
            entLayer.Color = Color.RoyalBlue;
            entLayer.Flags = 4;
            entLayer.Loaded(this.cadImage.Converter);
            this.cadImage.Converter.OnCreate(entLayer);
            this.cadImage.CurrentLayout.AddEntity(entLayer);

            //creation block
            CADBlock bl1 = new CADBlock();
            string sBlockName = "blimage";

            bl1 = (cadImage.Converter.GetSection(CADImport.FaceModule.ConvSection.Blocks).Entities[sBlockName] as CADBlock);

            if (bl1 == null)
               bl1 = new CADBlock();

            bl1.Name = sBlockName;
            bl1.Visibility = true;
            bl1.Visible = true;
            bl1.Layer = entLayer;

            //creation image
            Point p1 = new Point(0, 0);
            Point p2 = new Point(100, 75);
            Rectangle r1 = CADConst.SetNewRect(p1, p2);
            DPoint pt1 = new DPoint(r1.Left, r1.Top, 0);
            DPoint pt2 = new DPoint(r1.Right, r1.Bottom, 0);
            CADImageEnt image = new CADImageEnt();
            string path = @"c:\tmp\GenComposant.JPG";
            Bitmap bmpTmp;
 
            bmpTmp = new Bitmap(path);

            CADImageDef def = new CADImageDef();
            def.FileName = path;
            this.cadImage.Converter.Loads(def);

            image.ImageDef = def;
            image.Point = new DPoint(pt1.X, pt1.Y, 0);
            image.Size = new DPoint(r1.Width, r1.Height, 0);
            image.Loaded(this.cadImage.Converter);
            this.cadImage.Converter.ImageDefs.Add(image.ImageDef);
          
            bl1.AddEntity(image);

            //load block
            bl1.Loaded(this.cadImage.Converter);
            this.cadImage.Converter.OnCreate(bl1);
            this.cadImage.CurrentLayout.AddEntity(bl1);

            //creation + load insert
            CADInsert ins1 = new CADInsert();
            ins1.Block = bl1;
            ins1.Point = new DPoint(0, 0, 0);
            ins1.Visibility = true;
            ins1.Layer = entLayer;

            ins1.Loaded(this.cadImage.Converter);
            this.cadImage.Converter.OnCreate(ins1);
            this.cadImage.CurrentLayout.AddEntity(ins1);
           
            this.cadPictBox.Invalidate();

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat