Click or drag to resize

GraphDocumentExportActionsRenderAsEnhancedMetafileToStream Method

Renders a document as enhanced metafile. The metafile is rendered into a stream. You can create a metafile object afterwards from that stream.

Namespace: Altaxo.Graph.Gdi
Assembly: AltaxoBase (in AltaxoBase.dll) Version: 4.8.3179.0 (4.8.3179.0)
Syntax
C#
public static (int pixelsX, int pixelsY) RenderAsEnhancedMetafileToStream(
	Action<Graphics> renderingProc,
	Stream stream,
	PointD2D docSize,
	double sourceDpiResolution,
	double outputScalingFactor,
	PixelFormat pixelFormat = PixelFormat.Format32bppArgb
)

Parameters

renderingProc  ActionGraphics
Procedure for rendering the document. The argument is a graphics context, which is set to GraphicsUnits equal to Points. The drawing must be inside of the boundaries of docSize.X and docSize.Y.
stream  Stream
Destination stream. The metafile is rendered into this stream. The stream has to be writeable and seekable. At return, the position of the stream is set to 0, thus the stream is ready to be used to create a metafile object from it.
docSize  PointD2D
Size of the document in points (1/72 inch)
sourceDpiResolution  Double
The resolution in dpi of the source. This parameter is used only if creating the reference graphics context from the current printer fails. In this case, a context from a bitmap with the provided resolution is created.
outputScalingFactor  Double
Output scaling factor. If less than 1, the image will appear smaller than originally, if greater than 1, the image will appear larger than originally.
pixelFormat  PixelFormat  (Optional)
Optional: Only used if the graphics context can not be created from a printer document. Pixel format of the bitmap that is used in this case to construct the graphics context.

Return Value

ValueTupleInt32, Int32
The rendered enhanced metafile (vector format).
Remarks

I found no other way to realize different dpi resolutions, independently of screen or printer device contexts, as to patch the resulting metafile stream with informations about an 'artifical' device, which has exactly the resolution that is neccessary. By careful choice of the size of this artifical device one can avoid rounding errors concerning resolution and size. It happens that some programs (for instance MS Word 2010 when saving as PDF document) mess up the size of the metafile graphics, if the graphics was created with a PageUnit (of the graphics context) other than PIXELS. Thus I now always use PIXEL as PageUnit and scale the graphics context accordingly.

Another problem, which is actually without solution, is that e.g. MS Office will not show polylines with more than 8125 points. These polylines are included in the metafile, but MS Office seems to ignore them. On the other hand, CorelDraw X5 can show these polylines correctly. This problem might be related to the EmfPlus format, because MS Office will show these polylines if the EmfOnly format is used. But EmfOnly can not handle transparencies, thus it is not really a choice.

See Also