本文整理汇总了C#中System.Drawing.Imaging.Metafile.?.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Metafile.?.Dispose方法的具体用法?C# Metafile.?.Dispose怎么用?C# Metafile.?.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Imaging.Metafile
的用法示例。
在下文中一共展示了Metafile.?.Dispose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRtfImage
private static string GetRtfImage(Image image, Graphics gfx)
{
// Used to store the enhanced metafile
MemoryStream stream = null;
// Used to create the metafile and draw the image
Graphics graphics = gfx;
// The enhanced metafile
Metafile metaFile = null;
try
{
var rtf = new StringBuilder();
stream = new MemoryStream();
// Get the device context from the graphics context
IntPtr hdc = graphics.GetHdc();
// Create a new Enhanced Metafile from the device context
metaFile = new Metafile(stream, hdc);
// Release the device context
graphics.ReleaseHdc(hdc);
// Get a graphics context from the Enhanced Metafile
using (graphics = Graphics.FromImage(metaFile))
{
// Draw the image on the Enhanced Metafile
graphics.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height));
}
// Get the handle of the Enhanced Metafile
IntPtr hEmf = metaFile.GetHenhmetafile();
// A call to EmfToWmfBits with a null buffer return the size of the
// buffer need to store the WMF bits. Use this to get the buffer
// size.
uint bufferSize = GdiPlus.GdipEmfToWmfBits(hEmf, 0, null, 8, EmfToWmfBitsFlags.EmfToWmfBitsFlagsDefault);
// Create an array to hold the bits
var buffer = new byte[bufferSize];
// A call to EmfToWmfBits with a valid buffer copies the bits into the
// buffer an returns the number of bits in the WMF.
uint _convertedSize = GdiPlus.GdipEmfToWmfBits(hEmf, bufferSize, buffer, 8, EmfToWmfBitsFlags.EmfToWmfBitsFlagsDefault);
// Append the bits to the RTF string
foreach (byte t in buffer)
rtf.Append($"{t:X2}");
return rtf.ToString();
}
finally
{
graphics?.Dispose();
metaFile?.Dispose();
stream?.Close();
}
}