コード例 #1
0
        public static void Run()
        {
            //ExStart:ExportDXFToWMF
            // The path to the documents directory.
            string MyDir          = RunExamples.GetDataDir_DXFDrawings();
            string sourceFilePath = MyDir + "conic_pyramid.dxf";

            using (var image = Image.Load("NRB-GRID-BLOCK-MD-PROVALVDK-241000-162000-45400.dgn"))
            {
                var vectorOptions = new CadRasterizationOptions();
                vectorOptions.AutomaticLayoutsScaling = true;
                vectorOptions.BackgroundColor         = Color.Black;
                vectorOptions.PageWidth  = 500;
                vectorOptions.PageHeight = 500;

                WmfOptions wmfOptions = new WmfOptions()
                {
                    VectorRasterizationOptions = vectorOptions
                };

                image.Save("NRB-GRID-BLOCK-MD-PROVALVDK-241000-162000-45400.dgn.wmf", wmfOptions);
            }
            //ExEnd:ExportDXFToWMF
            Console.WriteLine("\nThe DXF drawing exported successfully to PDF.\nFile saved at " + MyDir);
        }
コード例 #2
0
        ///<Summary>
        /// ConvertImageFormat method to convert image to different image formats
        ///</Summary>
        public Response ConvertImageFormat(string fileName, string folderName, string outputType)
        {
            if (outputType.Equals("gif") || outputType.Equals("bmp") || outputType.Equals("jpg") || outputType.Equals("png") ||
                outputType.Equals("psd") || outputType.Equals("emf") || outputType.Equals("svg") || outputType.Equals("wmf"))
            {
                ImageOptionsBase optionsBase = new BmpOptions();

                if (outputType.Equals("jpg"))
                {
                    optionsBase = new JpegOptions();
                }
                else if (outputType.Equals("png"))
                {
                    optionsBase = new PngOptions();
                }
                else if (outputType.Equals("gif"))
                {
                    optionsBase = new GifOptions();
                }
                else if (outputType.Equals("psd"))
                {
                    optionsBase = new PsdOptions();
                }
                else if (outputType.Equals("emf"))
                {
                    optionsBase = new EmfOptions();
                }
                else if (outputType.Equals("svg"))
                {
                    optionsBase = new SvgOptions();
                }
                else if (outputType.Equals("wmf"))
                {
                    optionsBase = new WmfOptions();
                }
                return(ProcessTask(fileName, folderName, "." + outputType, true, true, delegate(string inFilePath, string outPath, string zipOutFolder)
                {
                    string fileExtension = Path.GetExtension(inFilePath).ToLower();
                    if ((fileExtension == ".tif") || (fileExtension == ".tiff"))
                    {
                        string outfileName = Path.GetFileNameWithoutExtension(fileName) + "_{0}";
                        using (TiffImage multiImage = (TiffImage)Image.Load(inFilePath))
                        {
                            if (multiImage.Frames.Length > 1)
                            {
                                int frameCounter = 0;
                                // Iterate over the TiffFrames in TiffImage
                                foreach (TiffFrame tiffFrame in multiImage.Frames)
                                {
                                    multiImage.ActiveFrame = tiffFrame;
                                    // Load Pixels of TiffFrame into an array of Colors
                                    Color[] pixels = multiImage.LoadPixels(tiffFrame.Bounds);
                                    // Create an instance of JpegOptions

                                    // Set the Source of JpegOptions as FileCreateSource by specifying the location where output will be saved
                                    // Last boolean parameter denotes isTemporal
                                    outPath = zipOutFolder + "/" + outfileName;

                                    optionsBase.Source = new FileCreateSource(string.Format(outPath, frameCounter + 1) + "." + outputType, false);
                                    // Create a new RasterImage of Jpeg type
                                    using (var jpgImage = (RasterImage)Image.Create(optionsBase, tiffFrame.Width, tiffFrame.Height))
                                    {
                                        // Save the JpegImage with pixels from TiffFrame
                                        jpgImage.SavePixels(tiffFrame.Bounds, pixels);
                                        // Resize the Jpeg Image
                                        jpgImage.Resize(100, 100, ResizeType.NearestNeighbourResample);
                                        // Save the results on disk
                                        jpgImage.Save();
                                    }
                                    frameCounter++;
                                }
                            }
                            else
                            {
                                multiImage.Save(outPath, optionsBase);
                            }
                        }
                    }
                    else

                    {
                        using (Image image = Image.Load(inFilePath))
                        {
                            image.Save(outPath, optionsBase);
                        }
                    }
                }));
            }

            return(new Response
            {
                FileName = null,
                Status = "Output type not found",
                StatusCode = 500
            });
        }