Wmf


Windows Metafile (WMF) is a graphics file format on Microsoft Windows systems. We can create it using c#

Most Windows clipart is in the WMF format. With vector graphics, a Windows Metafile can store an image in much less space than its raster graphics equivalent — 1% to 0.5% of the latter is not unusual. When embedded in documents, the storage space reductions are similarly impressive.

Following are the way of creating the WMF files in the memory.

Namespace part of metafile


using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Forms;


Following is the coding part of
creating MetaFile


   
class MemoryMetaFile: Form
{
MemoryStream MyMemoryStream = new MemoryStream();

public static void Main()
{
Application.Run(new CreateMetafile());
}
public CreateMetafile()
{
ResizeRedraw = true;

Graphics MyGraphics = CreateGraphics();
IntPtr MyIntPtr = grfx.GetHdc();

Metafile MyMetafile = new Metafile(MyMemoryStream, MyIntPtr);

MyGraphics.ReleaseHdc(MyIntPtr);
MyGraphics.Dispose();
MyGraphics = Graphics.FromImage(MyMetafile);
MyGraphics.DrawEllipse(Pens.Black, 0, 0, 100, 100);
MyGraphics.Dispose();
}
protected override void OnPaint(PaintEventArgs pea)
{
DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height);
}
protected void DoPage(Graphics MyGraphics, Color MyColor, int MyWidth, int MyHeight)
{
MyMemoryStream.Position = 0;
Metafile MyMetafile = new Metafile(MyMemoryStream);

for (int y = 0; y < MyHeight; y += MyMetafile .Height)
for (int x = 0; x < MyWidth; x += MyMetafile .Width)
grfx.DrawImage(MyMetafile, x, y, MyMetafile.Width,MyMetafile.Height);
}
}





By
Nathan


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: