public void ProcessEMF(byte[] emf) { try { _ms = new MemoryStream(emf); _mf = new Metafile(_ms); _bm = new Bitmap(1, 1); g = Graphics.FromImage(_bm); //XScale = Width / _mf.Width; //YScale = Height/ _mf.Height; m_delegate = new Graphics.EnumerateMetafileProc(MetafileCallback); g.EnumerateMetafile(_mf, new Point(0, 0), m_delegate); } finally { if (g != null) g.Dispose(); if (_bm != null) _bm.Dispose(); if (_ms != null) { _ms.Close(); _ms.Dispose(); } } }
// Method to draw the current emf memory stream private void ReportDrawPage(Graphics g) { if (null == m_currentPageStream || 0 == m_currentPageStream.Length || null == m_metafile) { return; } lock (this) { // Set the metafile delegate. int width = m_metafile.Width; int height = m_metafile.Height; m_delegate = new Graphics.EnumerateMetafileProc(MetafileCallback); // Draw in the rectangle Point[] points = new Point[3]; Point destPoint = new Point(0, 0); Point destPoint1 = new Point(width, 0); Point destPoint2 = new Point(0, height); points[0] = destPoint; points[1] = destPoint1; points[2] = destPoint2; g.EnumerateMetafile(m_metafile, points, m_delegate); // Clean up m_delegate = null; } }
protected void SaveViaBitmap(PrintDocument document, PrintPageEventArgs e) { int width = e.PageBounds.Width; int height = e.PageBounds.Height; using (Bitmap bitmap = new Bitmap((int)(width * _Scale), (int)(height * _Scale))) using (Graphics graphics = Graphics.FromImage(bitmap)) { graphics.Clear(Color.White); if (_Scale != 1) { graphics.ScaleTransform(_Scale, _Scale); } Point point = new Point(0, 0); Graphics.EnumerateMetafileProc callback = new Graphics.EnumerateMetafileProc(PlayRecord); graphics.EnumerateMetafile(_Metafile, point, callback); if (_Scale == 1 || true) { Save(bitmap); } else { using (Bitmap bitmap2 = new Bitmap(width, height)) using (Graphics graphics2 = Graphics.FromImage(bitmap2)) { graphics2.DrawImage(bitmap, 0, 0, width, height); Save(bitmap2); } } } }
protected void Play() { // try // { m_succeeded = false; Graphics.EnumerateMetafileProc metafileDelegate; Point destPoint; m_metafile = new Metafile(strFileName); if (!m_metafile.GetMetafileHeader().IsWmfPlaceable()) { m_metafile = RestorePlaceableHeader(m_metafile); } metafileDelegate = new Graphics.EnumerateMetafileProc(MetafileCallback); destPoint = new Point(20, 10); Graphics graphics = wf.CreateGraphics(); graphics.EnumerateMetafile(m_metafile, destPoint, metafileDelegate); // } // catch (Exception e) // { // Console.WriteLine(e.Message); // } }
// Method to draw the current emf memory stream private void ReportDrawPage(Graphics g) { if (null == m_currentPageStream || 0 == m_currentPageStream.Length || null == m_metafile) { return; } lock (this) { // Set the metafile delegate. m_metafile.SelectActiveFrame(FrameDimension.Page, m_currentPrintingPage - 1); int width = m_metafile.Width * 96 / 300; int height = m_metafile.Height * 96 / 300; m_delegate = MetafileCallback; // Draw in the rectangle Point[] points = new Point[3]; Point destPoint = new Point(0, 0); Point destPoint1 = new Point(width, 0); Point destPoint2 = new Point(0, height); points[0] = destPoint; points[1] = destPoint1; points[2] = destPoint2; g.EnumerateMetafile(m_metafile, points, m_delegate); points = null; // Clean up m_delegate = null; } }
public void ProcessEMF(byte[] emf) { try { _ms = new MemoryStream(emf); _mf = new Metafile(_ms); _bm = new Bitmap(1, 1); g = Graphics.FromImage(_bm); //XScale = Width / _mf.Width; //YScale = Height/ _mf.Height; m_delegate = new Graphics.EnumerateMetafileProc(MetafileCallback); g.EnumerateMetafile(_mf, new Point(0, 0), m_delegate); } finally { if (g != null) { g.Dispose(); } if (_bm != null) { _bm.Dispose(); } if (_ms != null) { _ms.Close(); _ms.Dispose(); } } }
private void button1_Click(object sender, EventArgs e) { Graphics.EnumerateMetafileProc metafileDelegate = MetafileCallback; metafile1 = new Metafile(@"F:\ProgrammingCases\GitHubProjects\1.emf"); // 遍历矢量图中的各个图元并有选择性的显示在 pictureBox1 中, 显示的矢量图的左上角点的位置为 destPoint pictureBox1.CreateGraphics().EnumerateMetafile(metafile1, destPoint: new Point(0, 0), callback: metafileDelegate); }
internal static partial int GdipEnumerateMetafileDestPointsI( #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif HandleRef graphics, #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif HandleRef metafile, Point *destPoints, int count, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif HandleRef imageattributes);
private void EnumerateMetaFile_Click(object sender, System.EventArgs e) { Graphics g = this.CreateGraphics(); g.Clear(this.BackColor); Metafile curMetafile = new Metafile(@"f:\mtfile.wmf"); Graphics.EnumerateMetafileProc enumMetaCB = new Graphics.EnumerateMetafileProc(EnumMetaCB); g.EnumerateMetafile(curMetafile, new Point(0, 0), enumMetaCB); curMetafile.Dispose(); g.Dispose(); }
protected void Play() { try { m_succeeded = false; Graphics.EnumerateMetafileProc metafileDelegate; Point destPoint; m_metafile = new Metafile(strFileName); metafileDelegate = new Graphics.EnumerateMetafileProc(MetafileCallback); destPoint = new Point(20, 10); Graphics graphics = wf.CreateGraphics(); graphics.EnumerateMetafile(m_metafile, destPoint, metafileDelegate); } catch (Exception e) { Console.WriteLine(e.Message); } }
private void EnumerateMetaFile_Click(object sender, System.EventArgs e) { // Create a Graphics object Graphics g = this.CreateGraphics(); g.Clear(this.BackColor); // Create a Metafile object from a file Metafile curMetafile = new Metafile("mtfile.wmf"); // Set EnumerateMetafileProc property Graphics.EnumerateMetafileProc enumMetaCB = new Graphics.EnumerateMetafileProc(EnumMetaCB); // Enumerate metafile g.EnumerateMetafile(curMetafile, new Point(0, 0), enumMetaCB); // Dispose curMetafile.Dispose(); g.Dispose(); }
/// <summary> ///Method to draw the current emf memory stream . /// </summary> /// <param name="g">The g.</param> private void ReportDrawPage(Graphics g) { if (null == this.currentPageStream || 0 == this.currentPageStream.Length || null == this.metaFile) { return; } lock (this) { // Set the metafile delegate. this.metaFileProcDelegate = new Graphics.EnumerateMetafileProc(this.MetafileCallback); // Draw in the rectangle Point destPoint = new Point(0, 0); g.EnumerateMetafile(this.metaFile, destPoint, this.metaFileProcDelegate); // Clean up this.metaFileProcDelegate = null; } }
public void EnumerateMetafile(Imaging.Metafile metafile, Point destPoint, Graphics.EnumerateMetafileProc callback) { throw new NotImplementedException(); }
// Method to draw the current emf memory stream private void ReportDrawPage(Graphics graphics) { if (m_currentPageStream == null || m_currentPageStream.Length == 0 || m_metafile == null) return; // Set metafile delegate. m_delegate = new Graphics.EnumerateMetafileProc(MetafileCallback); // Draw in the rectangle Point destPoint = new Point(0, 0); graphics.EnumerateMetafile(m_metafile, destPoint, m_delegate); // Clean up m_delegate = null; }
public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit unit, Graphics.EnumerateMetafileProc callback, IntPtr callbackData, System.Drawing.Imaging.ImageAttributes imageAttr) { throw new NotImplementedException(); }
public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit, Graphics.EnumerateMetafileProc callback, IntPtr callbackData) { throw new NotImplementedException(); }
internal static extern int GdipEnumerateMetafileSrcRectDestRectI(HandleRef graphics, HandleRef metafile, ref Rectangle destRect, ref Rectangle srcRect, GraphicsUnit pageUnit, Graphics.EnumerateMetafileProc callback, HandleRef callbackdata, HandleRef imageattributes);
private void Construct() { //replaceBrushCallback = new Graphics.EnumerateMetafileProc(ReplaceBrushCallbackProc); findReplaceColorCallback = new Graphics.EnumerateMetafileProc(FindReplaceColorCallbackProc); FindRemapColor(); }
internal static extern int GdipEnumerateMetafileSrcRectDestPointsI(HandleRef graphics, HandleRef metafile, Point *destPoints, int count, ref Rectangle srcRect, GraphicsUnit pageUnit, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, HandleRef imageattributes);
internal static extern int GdipEnumerateMetafileDestRectI(HandleRef graphics, HandleRef metafile, ref Rectangle destRect, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, HandleRef imageattributes);
// Method to draw the current emf memory stream private void ReportDrawPage(Graphics g) { if (null == m_currentPageStream || 0 == m_currentPageStream.Length || null == m_metafile) return; lock (this) { // Set the metafile delegate. int width = m_metafile.Width; int height = m_metafile.Height; m_delegate = new Graphics.EnumerateMetafileProc(MetafileCallback); // Draw in the rectangle Point[] points = new Point[3]; Point destPoint = new Point(0, 0); Point destPoint1 = new Point(width, 0); Point destPoint2 = new Point(0, height); points[0] = destPoint; points[1] = destPoint1; points[2] = destPoint2; g.EnumerateMetafile(m_metafile, points, m_delegate); // Clean up m_delegate = null; } }
/// <summary> /// 打印事件 /// </summary> protected override void doc_PrintPage(object sender, PrintPageEventArgs e) { if (printIndex == 2) { return; } _baseDoc = curDoublePrinters[printIndex].BaseDocument; if (_baseDoc.PagerSetting.AllowPage && _baseDoc.PagerSetting.PagerDesc.Count > 0) { _baseDoc.PageIndexChanged(_baseDoc.PagerSetting.PagerDesc[_pageIndex].PageIndex, _baseDoc.PagerSetting.PagerDesc[_pageIndex].IsMain, _baseDoc.DataSource); } _printMetafile = GetPageMetafile(); // 调整边距 Rectangle rect = new Rectangle(0, 0, _printMetafile.Width, _printMetafile.Height); double widthZoom = 1; double heightZoom = 1; double widthSize = (e.MarginBounds.Width); double heightSize = (e.MarginBounds.Height); // 宽度缩放 if (widthSize < rect.Width) { widthZoom = widthSize / rect.Width; } // 纵轴缩小 if (heightSize < rect.Height) { heightZoom = heightSize / rect.Height; } double zoom = (widthZoom < heightZoom) ? widthZoom : heightZoom; Rectangle zoomRect = new Rectangle(rect.X, rect.Y, (int)(rect.Width * zoom), (int)(rect.Height * zoom)); MemoryStream mStream = new MemoryStream(); Graphics tempGraphics = _baseDoc.CreateGraphics(); IntPtr ipHdctemp = tempGraphics.GetHdc(); Metafile mf = new Metafile(mStream, ipHdctemp); tempGraphics.ReleaseHdc(ipHdctemp); tempGraphics.Dispose(); Graphics gMf = Graphics.FromImage(mf); gMf.DrawImage(_printMetafile, zoomRect); gMf.Save(); gMf.Dispose(); _printMetafile = mf; metafileDelegate = new Graphics.EnumerateMetafileProc(MetafileCallback); // 开始正式打印 this.PrintPage(_printMetafile, e, zoomRect.Width, zoomRect.Height); metafileDelegate = null; _pageIndex++; if (_pageFromHeight) { Rectangle r = GetPrintRect(); if ((_pageIndex) * _pagePrintHeight < r.Height) { e.HasMorePages = true; } } else { if (printIndex == 0) { e.HasMorePages = true; } if (_baseDoc.PagerSetting.AllowPage && _pageIndex < _baseDoc.PagerSetting.TotalPageCount) { e.HasMorePages = true; } else { _pageIndex = 0; printIndex++; } } }
public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, Graphics.EnumerateMetafileProc callback) { throw new NotImplementedException(); }
protected virtual void doc_PrintPage(object sender, PrintPageEventArgs e) { //如果允许分页,则打印每一页,否则则打印当前页 if (_baseDoc.PagerSetting.AllowPage) { _baseDoc.PageIndexChanged(_baseDoc.PagerSetting.PagerDesc[_pageIndex].PageIndex, _baseDoc.PagerSetting.PagerDesc[_pageIndex].IsMain, _baseDoc.DataSource); } //创建 metafile _printMetafile = GetPageMetafile(); //_printMetafile.Save(@"D:\printMetafile0.emf"); //调整边距 Rectangle rect = new Rectangle(0, 0, _printMetafile.Width, _printMetafile.Height); double widthZoom = 1; double heightZoom = 1; double widthSize = (e.MarginBounds.Width); double heightSize = (e.MarginBounds.Height); if (widthSize < rect.Width) { widthZoom = widthSize / rect.Width; } //纵轴缩小 if (heightSize < rect.Height) { heightZoom = heightSize / rect.Height; } double zoom = (widthZoom < heightZoom) ? widthZoom : heightZoom; Rectangle zoomRect = new Rectangle(rect.X, rect.Y, (int)(rect.Width * zoom), (int)(rect.Height * zoom)); MemoryStream mStream = new MemoryStream(); Graphics ggggg = _baseDoc.CreateGraphics(); IntPtr ipHdctemp = ggggg.GetHdc(); Metafile mf = new Metafile(mStream, ipHdctemp); ggggg.ReleaseHdc(ipHdctemp); ggggg.Dispose(); Graphics gMf = Graphics.FromImage(mf); gMf.DrawImage(_printMetafile, zoomRect); gMf.Save(); gMf.Dispose(); _printMetafile = mf; //_printMetafile.Save(@"D:\printMetafile1.emf"); metafileDelegate = new Graphics.EnumerateMetafileProc(MetafileCallback); //开始正式打印 PrintPage(_printMetafile, e, zoomRect.Width, zoomRect.Height); metafileDelegate = null; _pageIndex++; if (_pageFromHeight) { Rectangle r = GetPrintRect(); if ((_pageIndex) * _pagePrintHeight < r.Height) { e.HasMorePages = true; } } else { if (_baseDoc.PagerSetting.AllowPage && _pageIndex < _baseDoc.PagerSetting.TotalPageCount) { e.HasMorePages = true; } else { _pageIndex = 0; } } }
internal static extern int GdipEnumerateMetafileDestPointI(HandleRef graphics, HandleRef metafile, ref Point destPoint, Graphics.EnumerateMetafileProc callback, HandleRef callbackdata, HandleRef imageattributes);
internal static partial int GdipEnumerateMetafileSrcRectDestRectI( #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif HandleRef graphics, #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif HandleRef metafile, ref Rectangle destRect, ref Rectangle srcRect, GraphicsUnit pageUnit, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif HandleRef imageattributes);
public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, RectangleF destRect, Graphics.EnumerateMetafileProc callback) { throw new NotImplementedException(); }
internal static extern int GdipEnumerateMetafileDestPointsI(HandleRef graphics, HandleRef metafile, Point *destPoints, int count, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, HandleRef imageattributes);
public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, Point destPoint, Graphics.EnumerateMetafileProc callback, IntPtr callbackData) { throw new NotImplementedException(); }
public Form1() { metafile1 = new Metafile(@"C:\Test.wmf"); metafileDelegate = new Graphics.EnumerateMetafileProc(MetafileCallback); destPoint = new Point(20, 10); }
public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, PointF[] destPoints, Graphics.EnumerateMetafileProc callback, IntPtr callbackData, System.Drawing.Imaging.ImageAttributes imageAttr) { throw new NotImplementedException(); }