Enumerate Metafile
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
class EnumMetafile: Form
{
Metafile mf;
Panel panel = new Panel();
public static void Main()
{
Application.Run(new EnumMetafile());
}
public EnumMetafile()
{
Splitter splitter = new Splitter();
splitter.Parent = this;
splitter.Dock = DockStyle.Left; // Right;
panel.Parent = this;
panel.Dock = DockStyle.Left;
panel.Paint += new PaintEventHandler(PanelOnPaint);
Menu = new MainMenu();
Menu.MenuItems.Add("&Open!", new EventHandler(MenuOpenOnClick));
}
void MenuOpenOnClick(object obj, EventArgs ea)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "All Metafiles|*.wmf;*.emf|" +
"Windows Metafile (*.wmf)|*.wmf|" +
"Enhanced Metafile (*.emf)|*.emf";
if (dlg.ShowDialog() == DialogResult.OK)
{
mf = new Metafile(dlg.FileName);
panel.Invalidate();
Graphics grfx = CreateGraphics();
grfx.EnumerateMetafile(mf, new Point(0, 0),
new Graphics.EnumerateMetafileProc(EnumMetafileProc));
grfx.Dispose();
}
}
bool EnumMetafileProc(EmfPlusRecordType eprt, int iFlags,
int iDataSize, IntPtr ipData,
PlayRecordCallback prc)
{
if (iDataSize > 0)
{
byte[] abyData = new Byte[iDataSize];
Marshal.Copy(ipData, abyData, 0, iDataSize);
foreach (byte by in abyData)
Console.WriteLine(" {0:X2}", by);
}
return true;
}
void PanelOnPaint(object obj, PaintEventArgs pea)
{
Panel panel = (Panel) obj;
Graphics grfx = pea.Graphics;
if (mf != null)
grfx.DrawImage(mf, 0, 0);
}
}
|
HTML code for linking to this page:
Related in same category :
-
-
-
-
|
|