由于EMF Plus dual具有GDI +记录和GDI记录(根据以下提到的来源):
https://docs.microsoft.com/en-us/windows/desktop/gdiplus/-gdiplus-metafiles-about
我需要找到一种枚举并仅获取GDI记录的方法。非常感谢您的帮助。
我使用以下代码枚举EMF文件,但它仅返回EMF加双图元文件格式的GDI +记录
Metafile curMetafile = new Metafile("sample.emf");
Graphics.EnumerateMetafileProc enumMetaCB = new Graphics.EnumerateMetafileProc(EnumFunction);
Form f = new Form();
f.ShowIcon = false;
f.Visible = false;
f.ShowInTaskbar = false;
f.Show();
Graphics g = f.CreateGraphics();
g.Clear(f.BackColor);
g.EnumerateMetafile(curMetafile, new Point(0, 0), enumMetaCB);
if (sw != null)
sw.Close();
f.Close();
curMetafile.Dispose();
g.Dispose();
public bool EnumFunction(EmfPlusRecordType recordType, int flags, int dataSize, IntPtr data, PlayRecordCallback cd)
{
byte[] dataArray = null;
if (data != IntPtr.Zero)
{
dataArray = new byte[dataSize];
Marshal.Copy(data, dataArray, 0, dataSize);
}
StringBuilder sb = new StringBuilder();
/* Convert binary data to hex String */
for (int i = 0; i < dataSize; ++i)
{
string DAT = Convert.ToString(dataArray[i], 16).ToUpper();
if (DAT.Length == 1)
DAT = "0" + DAT;
sb.Append(DAT + " ");
}
if (sw != null)
sw.WriteLine(recordType.ToString() + " " + flags + "(" + dataSize + " bytes) " /*+ sb.ToString()*/);
else
Console.Out.WriteLine(recordType.ToString() + " " + flags + "(" + dataSize + " bytes) " /*+ sb.ToString()*/);
return true;
}