Exemplo n.º 1
0
        public static void ShowFileExportMetafileDialog(this GraphDocument doc)
        {
            var opt = new GraphExportOptions();

            opt.TrySetImageAndPixelFormat(ImageFormat.Emf, PixelFormat.Format32bppArgb);
            ShowFileExportDialog(doc, opt);
        }
Exemplo n.º 2
0
        private void EnsureDropFileCreated()
        {
            var fileExtension = GraphExportOptions.GetDefaultFileNameExtension(_graphExportOptions.DropFileImageFormat);

            _graphDocumentDropdownFileName = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "AltaxoClipboardImage" + fileExtension);
            if (System.IO.File.Exists(_graphDocumentDropdownFileName))
            {
                try
                {
                    System.IO.File.Delete(_graphDocumentDropdownFileName);
                }
                catch (Exception)
                {
                    _graphDocumentDropdownFileName = null;
                    return;
                }
            }

            if (_graphExportOptions.DropFileImageFormat == System.Drawing.Imaging.ImageFormat.Emf)
            {
                if (!(null != _graphDocumentMetafileImage))
                {
                    throw new InvalidOperationException(nameof(_graphDocumentMetafileImage) + " should be != null");
                }

                var clonedMF = (System.Drawing.Imaging.Metafile)_graphDocumentMetafileImage.Clone(); // have to clone metafile because after calling GetHenhmetafile() metafile would be destroyed
                DataObjectHelper.SaveMetafileToDisk(clonedMF.GetHenhmetafile(), _graphDocumentDropdownFileName);
            }
            else if (_graphExportOptions.DropFileImageFormat == System.Drawing.Imaging.ImageFormat.Wmf)
            {
                using (var rgbBitmap = GraphDocumentExportActions.ConvertBitmapToPixelFormat(_graphDocumentBitmapImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb, _graphExportOptions.BackgroundColorForFormatsWithoutAlphaChannel))
                {
                    var scaledDocSize = _graphDocumentSize * _graphExportOptions.OutputScalingFactor;
                    using (var enhancedMetafile = GraphDocumentExportActions.RenderAsEnhancedMetafileBitmapFormat(rgbBitmap, scaledDocSize))
                    {
                        var hEmf  = enhancedMetafile.GetHenhmetafile();
                        var bytes = DataObjectHelper.ConvertEnhancedMetafileToWindowsMetafileBytes(hEmf);
                        var placeableHeaderBytes = DataObjectHelper.GetWmfPlaceableHeaderBytes(scaledDocSize);

                        using (var stream = new System.IO.FileStream(_graphDocumentDropdownFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Read))
                        {
                            stream.Write(placeableHeaderBytes, 0, placeableHeaderBytes.Length);
                            stream.Write(bytes, 0, bytes.Length);
                        }
                    }
                }
            }
            else // bitmap format
            {
                var bitmapToSave =
                    _graphExportOptions.DropFileBitmapPixelFormat == _graphDocumentBitmapImage.PixelFormat ?
                    _graphDocumentBitmapImage :
                    GraphDocumentExportActions.ConvertBitmapToPixelFormat(_graphDocumentBitmapImage, _graphExportOptions.DropFileBitmapPixelFormat, _graphExportOptions.BackgroundColorForFormatsWithoutAlphaChannel);

                bitmapToSave.Save(_graphDocumentDropdownFileName, _graphExportOptions.DropFileImageFormat);
            }
        }
Exemplo n.º 3
0
        public static void ShowFileExportTiffDialog(this GraphDocument doc)
        {
            var opt = new GraphExportOptions();

            opt.TrySetImageAndPixelFormat(ImageFormat.Tiff, PixelFormat.Format32bppArgb);
            opt.SourceDpiResolution      = 300;
            opt.DestinationDpiResolution = 300;
            ShowFileExportDialog(doc, opt);
        }
Exemplo n.º 4
0
        public static Bitmap RenderAsBitmap(this GraphDocument document, EmbeddedObjectRenderingOptions renderingOptions, PixelFormat pixelFormat = PixelFormat.Format32bppArgb)
        {
            BrushX opaqueGround = null;

            if (!GraphExportOptions.HasPixelFormatAlphaChannel(pixelFormat))
            {
                opaqueGround = new BrushX(renderingOptions.BackgroundColorForFormatsWithoutAlphaChannel);
            }

            return(RenderAsBitmap(document, opaqueGround, renderingOptions.BackgroundBrush, pixelFormat, renderingOptions.SourceDpiResolution, renderingOptions.SourceDpiResolution * renderingOptions.OutputScalingFactor));
        }
Exemplo n.º 5
0
        public static void ShowFileExportSpecificDialog(this GraphDocumentBase doc)
        {
            object resopt = _graphExportOptionsToFile;

            if (Current.Gui.ShowDialog(ref resopt, "Choose export options"))
            {
                _graphExportOptionsToFile = (GraphExportOptions)resopt;
            }
            else
            {
                return;
            }
            ShowFileExportDialog(doc, _graphExportOptionsToFile);
        }
Exemplo n.º 6
0
        /// <summary>Shows the dialog to choose the graph export options, and then the multi file export dialog.</summary>
        /// <param name="documents">List with graph documents to export.</param>
        public static void ShowExportMultipleGraphsDialogAndExportOptions(IEnumerable <Graph.GraphDocumentBase> documents)
        {
            object resopt = _graphExportOptionsToFile;

            if (Current.Gui.ShowDialog(ref resopt, "Choose export options"))
            {
                _graphExportOptionsToFile = (GraphExportOptions)resopt;
            }
            else
            {
                return;
            }

            ShowExportMultipleGraphsDialog(documents);
        }
Exemplo n.º 7
0
        public static void ShowFileExportDialog(this GraphDocumentBase doc, GraphExportOptions graphExportOptions)
        {
            var saveOptions = new Altaxo.Gui.SaveFileOptions();
            var list        = GetFileFilterString(graphExportOptions.ImageFormat);

            foreach (var entry in list)
            {
                saveOptions.AddFilter(entry.Key, entry.Value);
            }
            saveOptions.FilterIndex      = 0;
            saveOptions.RestoreDirectory = true;

            if (Current.Gui.ShowSaveFileDialog(saveOptions))
            {
                using (Stream myStream = new FileStream(saveOptions.FileName, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) // we need FileAccess.ReadWrite when exporting to EMF/WMF format
                {
                    var exporter = Current.ProjectService.GetProjectItemImageExporter(doc);
                    exporter?.ExportAsImageToStream(doc, graphExportOptions, myStream);
                    myStream.Close();
                } // end openfile ok
            }     // end dlgresult ok
        }
        private static string InternalAddClipboardDropDownList(Altaxo.Gui.IClipboardSetDataObject dao, System.Drawing.Bitmap bmp, GraphExportOptions options)
        {
            string filepath = System.IO.Path.GetTempPath();
            string filename = filepath + "AltaxoGraphCopyPage" + options.GetDefaultFileNameExtension();

            ;
            if (System.IO.File.Exists(filename))
            {
                System.IO.File.Delete(filename);
            }

            bmp.Save(filename, options.ImageFormat);

            var coll = new System.Collections.Specialized.StringCollection
            {
                filename
            };

            dao.SetFileDropList(coll);

            return(filename);
        }
		private static string InternalAddClipboardDropDownList(Altaxo.Gui.IClipboardSetDataObject dao, System.Drawing.Bitmap bmp, GraphExportOptions options)
		{
			string filepath = System.IO.Path.GetTempPath();
			string filename = filepath + "AltaxoGraphCopyPage" + options.GetDefaultFileNameExtension(); ;
			if (System.IO.File.Exists(filename))
				System.IO.File.Delete(filename);

			bmp.Save(filename, options.ImageFormat);

			System.Collections.Specialized.StringCollection coll = new System.Collections.Specialized.StringCollection();
			coll.Add(filename);
			dao.SetFileDropList(coll);

			return filename;
		}