1
Answer

metafiles and physical units

Ask a question
crain

crain

19y
2.1k
1
Hi, I am trying to create an enhanced metafile that draws several retangles. I want the rectangles to have physical dimensions in mm, so that they will be cut by a laser engraver in these units. The code below attempts to create an EMF with a single rectange 100mm by 100mm, but when I open it in Corel Draw, it says the rectangle is only 94.5mm by 88.6mm. Can anyone explain this disparity to me? public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // // Create temporary Graphics object for metafile // creation and get handle to its device context. Graphics newGraphics = this.CreateGraphics(); IntPtr hdc = newGraphics.GetHdc(); // Create metafile object to record. Metafile metaFile1 = new Metafile("SampMeta.emf", hdc); // Create graphics object to record metaFile. Graphics metaGraphics = Graphics.FromImage(metaFile1); //Set the graphics unit to mm metaGraphics.PageUnit = GraphicsUnit.Millimeter; // Draw rectangle in metaFile. metaGraphics.DrawRectangle(new Pen(Color.Black, 5), 0, 0, 100, 100); // Create comment and add to metaFile. byte[] metaComment = {(byte)'T', (byte)'e', (byte)'s', (byte)'t'}; metaGraphics.AddMetafileComment(metaComment); // Dispose of graphics object. metaGraphics.Dispose(); // Dispose of metafile. metaFile1.Dispose(); // Release handle to temporary device context. newGraphics.ReleaseHdc(hdc); // Dispose of scratch graphics object. newGraphics.Dispose(); } J Adam Crain UNC-CH Department of Physics and Astronomy [email protected]

Answers (1)