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"); } }
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); } }
public GraphDocumentDataObject(GraphDocumentBase graphDocument, ProjectFileComObject fileComObject, ComManager comManager) : base(comManager) { ComDebug.ReportInfo("{0} constructor.", GetType().Name); _dataAdviseHolder = new ManagedDataAdviseHolder(); _graphDocumentName = graphDocument.Name; _graphDocumentSize = graphDocument.Size; _graphExportOptions = graphDocument.GetPropertyValue(ClipboardRenderingOptions.PropertyKeyClipboardRenderingOptions, () => new ClipboardRenderingOptions()).Clone(); var embeddedRenderingOptions = graphDocument.GetPropertyValue(EmbeddedObjectRenderingOptions.PropertyKeyEmbeddedObjectRenderingOptions, () => null); if (null != embeddedRenderingOptions) { _graphExportOptions.CopyFrom(embeddedRenderingOptions); // merge embedded rendering options } if ((_graphExportOptions.RenderEnhancedMetafile && _graphExportOptions.RenderEnhancedMetafileAsVectorFormat) || (_graphExportOptions.RenderDropFile && _graphExportOptions.DropFileImageFormat == System.Drawing.Imaging.ImageFormat.Emf) ) { if (graphDocument is Altaxo.Graph.Gdi.GraphDocument) { _graphDocumentMetafileImage = GraphDocumentExportActions.RenderAsEnhancedMetafileVectorFormat((Altaxo.Graph.Gdi.GraphDocument)graphDocument, _graphExportOptions); } } if (null == _graphDocumentMetafileImage || _graphExportOptions.RenderBitmap || _graphExportOptions.RenderWindowsMetafile || (_graphExportOptions.RenderEnhancedMetafile && !_graphExportOptions.RenderEnhancedMetafileAsVectorFormat) || _graphExportOptions.RenderDropFile) { if (graphDocument is Altaxo.Graph.Gdi.GraphDocument) { _graphDocumentBitmapImage = GraphDocumentExportActions.RenderAsBitmap((Altaxo.Graph.Gdi.GraphDocument)graphDocument, _graphExportOptions.BackgroundBrush, System.Drawing.Imaging.PixelFormat.Format32bppArgb, _graphExportOptions.SourceDpiResolution, _graphExportOptions.SourceDpiResolution / _graphExportOptions.OutputScalingFactor); } else if (graphDocument is Altaxo.Graph.Graph3D.GraphDocument) { _graphDocumentBitmapImage = Altaxo.Graph.Graph3D.GraphDocumentExportActions.RenderAsBitmap((Altaxo.Graph.Graph3D.GraphDocument)graphDocument, _graphExportOptions.BackgroundBrush, System.Drawing.Imaging.PixelFormat.Format32bppArgb, _graphExportOptions.SourceDpiResolution, _graphExportOptions.SourceDpiResolution / _graphExportOptions.OutputScalingFactor); } else { throw new NotImplementedException(); } } if (_graphExportOptions.RenderEmbeddedObject) { var miniProjectBuilder = new Altaxo.Graph.Procedures.MiniProjectBuilder(); _altaxoMiniProject = miniProjectBuilder.GetMiniProject(graphDocument, true); } else { _altaxoMiniProject = null; } }
private void RenderPreview(GraphDocument doc) { if (null == _view) { return; } if (null != doc) { using (var bmp = GraphDocumentExportActions.RenderAsBitmap(doc, null, null, System.Drawing.Imaging.PixelFormat.Format32bppArgb, 150, 150)) { _view.SetPreviewBitmap("Preview of graph template:", bmp); } } else { _view.SetPreviewBitmap("No graph document selected", null); } }
/// <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)); } } }
private IntPtr RenderBitmapDIB(TYMED tymed) { ComDebug.ReportInfo("GraphDocumentDataObject.RenderBitmapDIB"); if (!(tymed == TYMED.TYMED_HGLOBAL)) { throw new ArgumentException(nameof(tymed) + " is not TYMED_HGLOBAL"); } if (null != _graphDocumentBitmapImage) { using (var convertedBitmap = GraphDocumentExportActions.ConvertBitmapToPixelFormat(_graphDocumentBitmapImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb, _graphExportOptions.BackgroundColorForFormatsWithoutAlphaChannel)) { return(DataObjectHelper.RenderDIBBitmapToHGLOBAL(convertedBitmap)); } } else { throw new InvalidProgramException("Please report this exception to the author of the program and describe the steps to reproduce the exception"); } }
/// <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()); } } }
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"); } }