Example #1
0
        private void exportAsButton__Click(object sender, EventArgs e)
        {
            if (metafileCanvas_.Metafile == null)
            {
                return;
            }

            using (var saveFileDialog = new SaveFileDialog())
            {
                var filters = new string[]
                {
                    "Bitmap Files (*.bmp;*.dib)|*.bmp;*.dib",
                    "JPEG Files (*.jpg;*.jpeg)|*.jpg;*.jpeg",
                    "PNG Files (*.png)|*.png",
                    "Windows Meta Files (*.emf;*.wmf)|*.emf;*.wmf",
                    "All Files (*.*)|*.*",
                };

                saveFileDialog.FileName    = Path.GetFileNameWithoutExtension(filePath_);
                saveFileDialog.Filter      = string.Join("|", filters);
                saveFileDialog.FilterIndex = 3;

                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    switch (Path.GetExtension(saveFileDialog.FileName).ToLower())
                    {
                    case ".emf":
#if false
                        // TODO:
                        // If orientation is changed, then the exported emf file can not be opened with
                        // this application anymore.
                        metafileCanvas_.Metafile.Save(saveFileDialog.FileName, ImageFormat.Emf);
#else
                        var metafile = metafileCanvas_.Metafile;
                        MetafileUtility.CopyMetafile(ref metafile, saveFileDialog.FileName);
                        metafileCanvas_.Metafile = metafile;
#endif
                        break;

                    case ".wmf":
                        metafile = metafileCanvas_.Metafile;
                        MetafileUtility.MetafileToWMF(ref metafile, saveFileDialog.FileName);
                        metafileCanvas_.Metafile = metafile;
                        break;

                    default:
                        using (var bitmap = MetafileUtility.MetafileToBitmap(metafileCanvas_.Metafile))
                        {
                            bitmap.Save(saveFileDialog.FileName);
                        }
                        break;
                    }
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            if (args.Length != 1 && args.Length != 2)
            {
                Console.WriteLine("Usage:\n\tEmfToWmf <input.emf> [output.wmf]\n");
                return;
            }

            var inputEmfFilePath  = args[0];
            var outputWmfFilepath = args.Length == 2 ? args[1] : Path.ChangeExtension(inputEmfFilePath, ".wmf");

#if false
            using (var metafile = new Metafile(inputEmfFilePath))
                MetafileUtility.MetafileToWMF(metafile, outputWmfFilepath);
#else
            using (var metafile = new Metafile(inputEmfFilePath))
                using (var outputFile = new FileStream(outputWmfFilepath, FileMode.CreateNew))
                {
                    var bytes = MetafileUtility.GetMetafileRawBytes(metafile);
                    outputFile.Write(bytes, 0, bytes.Length);
                }
#endif
        }