示例#1
0
        public static void Run()
        {
            try
            {
                //ExStart:ExportDGNToRasterImage
                // The path to the documents directory.
                string MyDir          = RunExamples.GetDataDir_ExportingDGN();
                string sourceFilePath = MyDir + "Nikon_D90_Camera.dgn";
                // Load an existing DGN file as CadImage.
                using (Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(sourceFilePath))
                {
                    // Create an object of DgnRasterizationOptions class and define/set different properties
                    Aspose.CAD.ImageOptions.DgnRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.DgnRasterizationOptions();
                    rasterizationOptions.PageWidth               = 600;
                    rasterizationOptions.PageHeight              = 300;
                    rasterizationOptions.CenterDrawing           = true;
                    rasterizationOptions.NoScaling               = true;
                    rasterizationOptions.AutomaticLayoutsScaling = false;

                    // Create an object of JpegOptions class as we are converting the DGN to jpeg and assign DgnRasterizationOptions object to it.
                    Aspose.CAD.ImageOptionsBase options = new Aspose.CAD.ImageOptions.JpegOptions();
                    options.VectorRasterizationOptions = rasterizationOptions;

                    // Call the save method of the CadImage class object.
                    cadImage.Save(MyDir + "ExportDGNToRasterImage_out.pdf", options);
                }
                //ExEnd:ExportDGNToRasterImage
                Console.WriteLine("\nThe DGN file exported successfully to raster image.\nFile saved at " + MyDir);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Please use valid input file." + ex.Message);
            }
        }
示例#2
0
        public static void Run()
        {
            //ExStart:CADLayersToRasterImageFormats
            // The path to the documents directory.
            string MyDir          = RunExamples.GetDataDir_ConvertingCAD();
            string sourceFilePath = MyDir + "conic_pyramid.dxf";

            // Load a CAD drawing in an instance of Image
            using (var image = Aspose.CAD.Image.Load(sourceFilePath))
            {
                // Create an instance of CadRasterizationOptions
                var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
                // Set image width & height
                rasterizationOptions.PageWidth  = 500;
                rasterizationOptions.PageHeight = 500;

                // Set the drawing to render at the center of image
                rasterizationOptions.CenterDrawing = true;

                // Add the layer name to the CadRasterizationOptions's layer list
                rasterizationOptions.Layers = new string[] { "LayerA" };
                // Create an instance of JpegOptions (or any ImageOptions for raster formats)
                var options = new Aspose.CAD.ImageOptions.JpegOptions();
                // Set VectorRasterizationOptions property to the instance of CadRasterizationOptions
                options.VectorRasterizationOptions = rasterizationOptions;
                //Export each layer to Jpeg format
                MyDir = MyDir + "CADLayersToRasterImageFormats_out.jpg";
                image.Save(MyDir, options);
            }

            Console.WriteLine("\nCAD layers converted successfully to raster image format.\nFile saved at " + MyDir);
        }
        public static void ConvertAllLayersToRasterImageFormats()
        {
            //ExStart:ConvertAllLayersToRasterImageFormats
            // The path to the documents directory.
            string MyDir          = RunExamples.GetDataDir_ConvertingCAD();
            string sourceFilePath = MyDir + "conic_pyramid.dxf";

            // Load a CAD drawing in an instance of CadImage
            using (var image = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(sourceFilePath))
            {
                // Create an instance of CadRasterizationOptions
                var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
                // Set image width & height
                rasterizationOptions.PageWidth  = 500;
                rasterizationOptions.PageHeight = 500;
                // Set the drawing to render at the center of image
                rasterizationOptions.CenterDrawing = true;

                // Get the layers in an instance of CadLayersDictionary
                var layers = image.Layers;
                // Iterate over the layers
                foreach (var layer in layers.ValuesTyped)
                {
                    // Display layer name for tracking
                    Console.WriteLine("Start with " + layer.Name);

                    // Add the layer name to the CadRasterizationOptions's layer list
                    rasterizationOptions.Layers.Add(layer.Name);

                    // Create an instance of JpegOptions (or any ImageOptions for raster formats)
                    var options = new Aspose.CAD.ImageOptions.JpegOptions();
                    // Set VectorRasterizationOptions property to the instance of CadRasterizationOptions
                    options.VectorRasterizationOptions = rasterizationOptions;
                    // Export each layer to Jpeg format
                    image.Save(layer.Name + "_out_.jpg", options);
                }
            }
            //ExEnd:ConvertAllLayersToRasterImageFormats
            Console.WriteLine("\nCAD all layers converted successfully to raster image format.");
        }
示例#4
0
        public static void Run()
        {
            //ExStart:ExportSpecificDXFLayoutToImage

            // The path to the documents directory.
            string MyDir          = RunExamples.GetDataDir_DXFDrawings();
            string sourceFilePath = MyDir + "for_layers_test.dwf";

            using (var image = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(sourceFilePath))
            {
                // Create an instance of CadRasterizationOptions
                var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
                // Set image width & height
                rasterizationOptions.PageWidth  = 500;
                rasterizationOptions.PageHeight = 500;
                // Set the drawing to render at the center of image
                // rasterizationOptions.CenterDrawing = true;

                // Get the layers in an instance of CadLayersDictionary
                var layersList = image.Layers;
                // Iterate over the layers
                foreach (var layerName in layersList.GetLayersNames())
                {
                    // Display layer name for tracking
                    Console.WriteLine("Start with " + layerName);

                    // Add the layer name to the CadRasterizationOptions's layer list
                    rasterizationOptions.Layers = new string[] { "LayerA" };
                    // Create an instance of JpegOptions (or any ImageOptions for raster formats)
                    var options = new Aspose.CAD.ImageOptions.JpegOptions();
                    // Set VectorRasterizationOptions property to the instance of CadRasterizationOptions
                    options.VectorRasterizationOptions = rasterizationOptions;
                    //Export each layer to Jpeg format
                    image.Save(layerName + "_out.jpg", options);
                }
            }
            //ExEnd:ExportSpecificDXFLayoutToImage
        }
        private List <string> GetDocumentPages(string file, string folderName, int currentPage)
        {
            List <string> lstOutput   = new List <string>();
            string        outfileName = "page_{0}";
            string        outPath     = Config.Configuration.OutputDirectory + folderName + "/" + outfileName;

            currentPage = currentPage - 1;
            Directory.CreateDirectory(Config.Configuration.OutputDirectory + folderName);
            string imagePath = string.Format(outPath, currentPage) + ".jpeg";

            if (System.IO.File.Exists(imagePath) && currentPage > 0)
            {
                lstOutput.Add(imagePath);
                return(lstOutput);
            }

            int i = currentPage;

            var filename = System.IO.File.Exists(Config.Configuration.WorkingDirectory + folderName + "/" + file)
                                ? Config.Configuration.WorkingDirectory + folderName + "/" + file
                                : Config.Configuration.OutputDirectory + folderName + "/" + file;

            using (FilePathLock.Use(filename))
            {
                try
                {
                    Aspose.CAD.Live.Demos.UI.Models.License.SetAsposeCADLicense();


                    // Load an existing CAD document
                    Aspose.CAD.FileFormats.Cad.CadImage image = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(filename);

                    // Create an instance of CadRasterizationOptions
                    Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();

                    // Set image width & height
                    rasterizationOptions.PageWidth  = 1024;
                    rasterizationOptions.PageHeight = 1024;
                    // Set the drawing to render at the center of image
                    //rasterizationOptions.CenterDrawing = true;
                    //rasterizationOptions.TypeOfEntities = Aspose.CAD.ImageOptions.TypeOfEntities.Entities3D;

                    rasterizationOptions.AutomaticLayoutsScaling = true;
                    rasterizationOptions.NoScaling       = false;
                    rasterizationOptions.ContentAsBitmap = true;

                    // Set Graphics options
                    rasterizationOptions.GraphicsOptions.SmoothingMode     = Aspose.CAD.SmoothingMode.HighQuality;
                    rasterizationOptions.GraphicsOptions.TextRenderingHint = Aspose.CAD.TextRenderingHint.AntiAliasGridFit;
                    rasterizationOptions.GraphicsOptions.InterpolationMode = Aspose.CAD.InterpolationMode.HighQualityBicubic;


                    // Get the layers in an instance of CadLayersDictionary
                    var layersList = image.Layers;
                    lstOutput.Add(layersList.Count.ToString());
                    i = 0;
                    // Iterate over the layers
                    foreach (var layerName in layersList.GetLayersNames())
                    {
                        if (i == currentPage)
                        {
                            // Add the layer name to the CadRasterizationOptions's layer list
                            rasterizationOptions.Layers[i] = layerName;

                            // Create an instance of PngOptions for the resultant image
                            Aspose.CAD.ImageOptions.JpegOptions options = new Aspose.CAD.ImageOptions.JpegOptions();

                            // Set rasterization options
                            options.VectorRasterizationOptions = rasterizationOptions;
                            image.Save(imagePath, options);
                            lstOutput.Add(imagePath);
                            image.Dispose();
                            break;
                        }
                        i++;
                    }
                    if (!image.Disposed)
                    {
                        image.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                return(lstOutput);
            }
        }