Esempio n. 1
0
        private IntPtr RenderWindowsMetafilePict(TYMED tymed)
        {
            ComDebug.ReportInfo("GraphDocumentDataObject.RenderWindowsMetafilePict");

            if (!(tymed == TYMED.TYMED_MFPICT))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_MFPICT");
            }

            if (null != _graphDocumentBitmapImage)
            {
                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();
                        return(DataObjectHelper.ConvertEnhancedMetafileToWindowsMetafilePict(hEmf, scaledDocSize.X, scaledDocSize.Y));
                    }
                }
            }
            else
            {
                throw new InvalidProgramException("Please report this exception to the author of the program and describe the steps to reproduce the exception");
            }
        }
Esempio 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);
            }
        }
        /// <summary>
        /// Renders the provided graph document to an windows metafile picture (TYMED_MFPICT). Please not that this format does not support transparancy, thus the back color provided in the rendering options is used as ground brush first.
        /// </summary>
        /// <param name="tymed">The tymed to check.</param>
        /// <param name="document">The graph document.</param>
        /// <returns>Pointer to windows metafile picture (TYMED_MFPICT).</returns>
        public static IntPtr RenderWindowsMetafilePict_TYMED_MFPICT(TYMED tymed, GraphDocumentBase document)
        {
            if (!(tymed == TYMED.TYMED_MFPICT))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_MFPICT");
            }

            var renderingOptions = GetRenderingOptions(document);

            using (var rgbBitmap = Altaxo.Graph.GraphDocumentBaseExportActions.RenderAsBitmap(document, renderingOptions, System.Drawing.Imaging.PixelFormat.Format24bppRgb))
            {
                var scaledDocSize = document.Size * renderingOptions.OutputScalingFactor;

                using (var enhancedMetafile = GraphDocumentExportActions.RenderAsEnhancedMetafileBitmapFormat(rgbBitmap, scaledDocSize))
                {
                    var hEmf = enhancedMetafile.GetHenhmetafile();
                    return(DataObjectHelper.ConvertEnhancedMetafileToWindowsMetafilePict(hEmf, scaledDocSize.X, scaledDocSize.Y));
                }
            }
        }
        /// <summary>
        /// Renders the provided graph document to an enhanced metafile (TYMED_ENHMF).
        /// </summary>
        /// <param name="tymed">The tymed to check.</param>
        /// <param name="document">The graph document.</param>
        /// <returns>Pointer to the enhanced metafile (TYMED_ENHMF).</returns>
        public static IntPtr RenderEnhancedMetafile_TYMED_ENHMF(TYMED tymed, GraphDocumentBase document)
        {
            if (!(tymed == TYMED.TYMED_ENHMF))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_TYMED_ENHMF");
            }

            var renderingOptions = GetRenderingOptions(document);

            if (renderingOptions.RenderEnhancedMetafileAsVectorFormat)
            {
                var metafile = Altaxo.Graph.GraphDocumentBaseExportActions.RenderAsEnhancedMetafileVectorFormat(document, renderingOptions);
                return(metafile.GetHenhmetafile());
            }
            else
            {
                using (var bmp = Altaxo.Graph.GraphDocumentBaseExportActions.RenderAsBitmap(document, renderingOptions, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                {
                    var scaledDocSize = document.Size * renderingOptions.OutputScalingFactor;
                    return(GraphDocumentExportActions.RenderAsEnhancedMetafileBitmapFormat(bmp, scaledDocSize).GetHenhmetafile());
                }
            }
        }
Esempio n. 5
0
        private IntPtr RenderEnhancedMetaFile(TYMED tymed)
        {
            ComDebug.ReportInfo("GraphDocumentDataObject.RenderEnhancedMetafile");

            if (!(tymed == TYMED.TYMED_ENHMF))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_TYMED_ENHMF");
            }

            if (null != _graphDocumentMetafileImage)
            {
                var mfCloned = (System.Drawing.Imaging.Metafile)_graphDocumentMetafileImage.Clone();
                return(mfCloned.GetHenhmetafile());
            }
            else if (null != _graphDocumentBitmapImage)
            {
                var scaledDocSize = _graphDocumentSize * _graphExportOptions.OutputScalingFactor;
                return(GraphDocumentExportActions.RenderAsEnhancedMetafileBitmapFormat(_graphDocumentBitmapImage, scaledDocSize).GetHenhmetafile());
            }
            else
            {
                throw new InvalidProgramException("Please report this exception to the author of the program and describe the steps to reproduce the exception");
            }
        }