private static void ImageClippingBoundary()
        {
            ImageDefinition imageDef = new ImageDefinition(@".\img\image02.jpg", "MyImage");
            imageDef.ResolutionUnits = ImageResolutionUnits.Centimeters;
            double width = imageDef.Width / imageDef.HorizontalResolution;
            double height = imageDef.Height / imageDef.VerticalResolution;
            Image image = new Image(imageDef, new Vector2(0, 0), width, height);
            image.Rotation = 30;


            // the coordinates of the clipping boundary are relative to the image with its actual dimensions and not to the width and height of its definition.
            // this clipping boundary will only show the middle center of the image.
            double x = width / 4;
            double y = height / 4;
            ClippingBoundary clip = new ClippingBoundary(x, y, 2 * x, 2 * y);
            image.ClippingBoundary = clip;

            DxfDocument doc = new DxfDocument();
            doc.AddEntity(image);
            doc.Save("image.dxf");

            DxfDocument test = DxfDocument.Load("image.dxf");
            test.Save("test.dxf");
        }
        private static void WriteImage()
        {
            ImageDefinition imageDefinition = new ImageDefinition("img\\image01.jpg");
            Image image = new Image(imageDefinition, Vector3.Zero, 10, 10);

            XData xdata1 = new XData(new ApplicationRegistry("netDxf"));
            xdata1.XDataRecord.Add(new XDataRecord(XDataCode.String, "xData image position"));
            xdata1.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata1.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionX, image.Position.X));
            xdata1.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionY, image.Position.Y));
            xdata1.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionZ, image.Position.Z));
            xdata1.XDataRecord.Add(XDataRecord.CloseControlString);
            image.XData.Add(xdata1);

            //image.Normal = new Vector3(1, 1, 1);
            //image.Rotation = 30;

            // you can pass a name that must be unique for the image definiton, by default it will use the file name without the extension
            ImageDefinition imageDef2 = new ImageDefinition("img\\image02.jpg", "MyImage");
            Image image2 = new Image(imageDef2, new Vector3(0, 150, 0), 10, 10);
            Image image3 = new Image(imageDef2, new Vector3(150, 150, 0), 10, 10);

            // clipping boundary definition in local coordinates
            ClippingBoundary clip = new ClippingBoundary(100, 100, 500, 300);
            image.ClippingBoundary = clip;
            // set to null to restore the default clipping boundary (full image)
            image.ClippingBoundary = null;

            // images can be part of a block definition
            Block block = new Block("ImageBlock");
            block.Entities.Add(image2);
            block.Entities.Add(image3);
            Insert insert = new Insert(block, new Vector3(0, 100, 0));

            DxfDocument dxf = new DxfDocument();

            dxf.AddEntity(image);
            //dxf.AddEntity(image2);
            //dxf.AddEntity(image3);
            dxf.AddEntity(insert);

            dxf.Save("image.dxf");
            dxf = DxfDocument.Load("image.dxf");
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2010;
            dxf.Save("test.dxf");

            //dxf.RemoveEntity(image2);
            //dxf.Save("image2.dxf");
            //dxf.RemoveEntity(image3);
            //dxf.RemoveEntity(image);
            //dxf.Save("image3.dxf");

        }