Enhanced Metafiles (EMF) are vector files capable of high resolution graphics and small in size.
Open test.emf in Windows Picture and Fax Viewer and try the zoom
Change miBmp_Click in '\Samples C#\DocumentViewer\Viewer.cs' to the following.
Code:
private void miBmp_Click(object sender, System.EventArgs e)
{
int page = this.pagePreview.Page;
// Reuse the renderer from the preview
DocumentRenderer renderer = this.pagePreview.Renderer;
PageInfo info = renderer.FormattedDocument.GetPageInfo(page);
// Create an image
int dpi = 150;
int dx, dy;
if (info.Orientation == PdfSharp.PageOrientation.Portrait)
{
dx = (int)(info.Width.Inch * dpi);
dy = (int)(info.Height.Inch * dpi);
}
else
{
dx = (int)(info.Height.Inch * dpi);
dy = (int)(info.Width.Inch * dpi);
}
// Image image = new Bitmap(dx, dy, PixelFormat.Format32bppRgb);
// Get the graphics object for creating the metafile
FileStream fileStream = new FileStream("test.emf", FileMode.OpenOrCreate, FileAccess.Write);
Graphics gr = CreateGraphics();
IntPtr hDC = gr.GetHdc();
Metafile image = new Metafile(fileStream, hDC, new Rectangle(0, 0, dx, dy), MetafileFrameUnit.Pixel, EmfType.EmfPlusOnly);
// Don't need this graphics object any more
gr.ReleaseHdc(hDC);
gr.Dispose();
// Create a Graphics object for the image and scale it for drawing with 72 dpi
Graphics graphics = Graphics.FromImage(image);
graphics.Clear(System.Drawing.Color.White);
float scale = dpi / 72f;
graphics.ScaleTransform(scale, scale);
// Create an XGraphics object and render the page
XGraphics gfx = XGraphics.FromGraphics(graphics, new XSize(info.Width.Point, info.Height.Point));
renderer.RenderPage(gfx, page);
gfx.Dispose();
// Close the file
fileStream.Close();
// image.Save("test.png", ImageFormat.Png);
Process.Start("mspaint", "test.emf"); // Use MSPaint, not Photoshop...
// Process.Start("mspaint", "test.png"); // Use MSPaint, not Photoshop...
}