当前位置: 首页>>代码示例>>C#>>正文


C# Imaging.Metafile类代码示例

本文整理汇总了C#中System.Drawing.Imaging.Metafile的典型用法代码示例。如果您正苦于以下问题:C# Metafile类的具体用法?C# Metafile怎么用?C# Metafile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Metafile类属于System.Drawing.Imaging命名空间,在下文中一共展示了Metafile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawTree

        private static void DrawTree(TreeNode treeNode, string file)
        {
            using (Metafile mf = new Metafile(file, Graphics.FromHwnd(IntPtr.Zero).GetHdc(), EmfType.EmfOnly))
            {
                using (Graphics graphics = Graphics.FromImage(mf))
                {
                    graphics.PageUnit = GraphicsUnit.Point;

                    Font labelFont = new Font("SimSun", 9.0f, FontStyle.Regular, GraphicsUnit.Point);
                    DrawTreeContext context = new DrawTreeContext()
                    {
                        Graphics = graphics,
                        BorderPen = new Pen(Color.Black, 0.75f),
                        ConnectorPen = new Pen(Color.Black, 0.5f),
                        LabelBrush = Brushes.Black,
                        LabelFont = labelFont,
                        LabelHeight = labelFont.Size,
                        NodeHorizontalSep = 9.0,
                        NodeVerticalSep = 24.0,
                        NodeHorizontalPadding = 3.75,
                        NodeVerticalPadding = 3.75,
                        PreferCjk = true
                    };

                    treeNode.DrawTree(context, new PointD(treeNode.Layout(context).Pivot, 0.0));
                }
            }
        }
开发者ID:EFanZh,项目名称:EFanZh,代码行数:28,代码来源:Program.cs

示例2: Save

		/// <summary>
		/// Saves the specified <see cref="Metafile"/> at the specified path.
		/// </summary>
		/// 
		/// <exception cref="ArgumentNullException">
		/// <para>
		///		<paramref name="path"/> is <see langword="null"/>.
		/// </para>
		/// -or-
		/// <para>
		///		<paramref name="path"/> is an empty string.
		/// </para>
		/// -or-
		/// <para>
		///		<paramref name="metafileToSave"/> is <see langword="null"/>.
		/// </para>
		/// </exception>
		public static void Save(string path, Metafile metafileToSave)
		{
			if (string.IsNullOrEmpty(path))
			{
				throw new ArgumentNullException("path");
			}

			if (metafileToSave == null)
			{
				throw new ArgumentNullException("metafileToSave");
			}

			FileStream stream = null;

			try
			{
				stream = new FileStream(path, FileMode.Create);
				Save(stream, metafileToSave);
			}
			catch
			{
				throw;
			}
			finally
			{
				if (stream != null)
				{
					stream.Flush();
					stream.Close();
				}
			}
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:49,代码来源:NuGenMetafileSaver.cs

示例3: OnPrintPage

            protected override void OnPrintPage(PrintPageEventArgs e)
            {
                base.OnPrintPage(e);

                Stream pageToPrint = m_pages[m_currentPage];
                pageToPrint.Position = 0;

                // Load each page into a Metafile to draw it.
                using (Metafile pageMetaFile = new Metafile(pageToPrint))
                {
                    Rectangle adjustedRect = new Rectangle(
                            e.PageBounds.Left - (int)e.PageSettings.HardMarginX,
                            e.PageBounds.Top - (int)e.PageSettings.HardMarginY,
                            e.PageBounds.Width,
                            e.PageBounds.Height);

                    // Draw a white background for the report
                    e.Graphics.FillRectangle(Brushes.White, adjustedRect);

                    // Draw the report content
                    e.Graphics.DrawImage(pageMetaFile, adjustedRect);

                    // Prepare for next page.  Make sure we haven't hit the end.
                    m_currentPage++;
                    e.HasMorePages = m_currentPage < m_pages.Count;
                }
            }
开发者ID:FJSOTO,项目名称:Tienda-Plaza,代码行数:27,代码来源:AutoPrintCls.cs

示例4: CreateMetafile

        /// <summary>
        /// Create image metafile constructor
        /// </summary>
        /// <param name="Width">Image width in pixels.</param>
        /// <param name="Height">Image height in pixels.</param>
        public CreateMetafile(
			Int32	Width,
			Int32	Height
			)
        {
            using (MemoryStream Stream = new MemoryStream())
            {
            using (Graphics MemoryGraphics = Graphics.FromHwndInternal(IntPtr.Zero))
                {
                IntPtr deviceContextHandle = MemoryGraphics.GetHdc();
                Metafile = new Metafile(Stream, deviceContextHandle, new RectangleF(0, 0, Width, Height), MetafileFrameUnit.Pixel, EmfType.EmfPlusOnly);
                MemoryGraphics.ReleaseHdc();
                }
            }

            Graphics = Graphics.FromImage(Metafile);

            // Set everything to high quality
            Graphics.SmoothingMode = SmoothingMode.HighQuality;
            Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
            Graphics.CompositingQuality = CompositingQuality.HighQuality;
             		Graphics.PageUnit = GraphicsUnit.Pixel;
            return;
        }
开发者ID:UnionMexicanaDelNorte,项目名称:cheques,代码行数:30,代码来源:CreateMetafile.cs

示例5: PutEnhMetafileOnClipboard

 /// <summary>
 /// Copies the given <see cref="T:System.Drawing.Imaging.MetaFile" /> to the clipboard.
 /// The given <see cref="T:System.Drawing.Imaging.MetaFile" /> is set to an invalid state inside this function.
 /// </summary>
 public static bool PutEnhMetafileOnClipboard(IntPtr hWnd, Metafile metafile, bool clearClipboard)
 {
     if (metafile == null) throw new ArgumentNullException("metafile");
     bool bResult = false;
     IntPtr hEMF, hEMF2;
     hEMF = metafile.GetHenhmetafile(); // invalidates mf
     if (!hEMF.Equals(IntPtr.Zero)) {
         try {
             hEMF2 = CopyEnhMetaFile(hEMF, null);
             if (!hEMF2.Equals(IntPtr.Zero)) {
                 if (OpenClipboard(hWnd)) {
                     try {
                         if (clearClipboard) {
                             if (!EmptyClipboard())
                                 return false;
                         }
                         IntPtr hRes = SetClipboardData(14 /*CF_ENHMETAFILE*/, hEMF2);
                         bResult = hRes.Equals(hEMF2);
                     } finally {
                         CloseClipboard();
                     }
                 }
             }
         } finally {
             DeleteEnhMetaFile(hEMF);
         }
     }
     return bResult;
 }
开发者ID:LudovicT,项目名称:NShape,代码行数:33,代码来源:EmfHelper.cs

示例6: OnStartPage

        public override Graphics OnStartPage(PrintDocument document, PrintPageEventArgs e)
        {
            Bitmap bmp = new Bitmap(1, 1);

            Graphics bmpg = Graphics.FromImage(bmp);
            IntPtr hdc = bmpg.GetHdc();
            ms = new MemoryStream();
            Metafile meta = new Metafile(ms, hdc, EmfType.EmfPlusDual);
            bmpg.ReleaseHdc(hdc);

            this.pic.Image = meta;

            Graphics g = Graphics.FromImage(meta);

            PaperSize size = e.PageSettings.PaperSize;
            int height = size.Height * dpi / 100;
            int width = size.Width * dpi / 100;

            if (e.PageSettings.Landscape)
            {
                g.FillRectangle(Brushes.White, 0, 0, height, width);
                g.SetClip(new Rectangle(0, 0, height - 16, width - 16));
            }
            else
            {
                g.FillRectangle(Brushes.White, 0, 0, width, height);
                g.SetClip(new Rectangle(0, 0, width - 16, height - 16));
            }

            return g;
        }
开发者ID:JosonYang,项目名称:aojreporter,代码行数:31,代码来源:AojPrintPreviewControl.cs

示例7: ExportImage

        public void ExportImage(string filename)
        {
            switch (Path.GetExtension(filename).ToLower())
              {
            case ".png":
              Bitmap bmp = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);
              using (Graphics g = Graphics.FromImage(bmp))
              {
            _chart.Draw(g);
            bmp.Save(filename);
              }
              break;

            case ".emf":
              using (Graphics g = this.CreateGraphics())
              {
            IntPtr hdc = g.GetHdc();

            Metafile mf = new Metafile(filename, hdc);

            using (Graphics mg = Graphics.FromImage(mf))
            {
              using (mf)
              {
                _chart.Draw(mg);
              }
            }

            g.ReleaseHdc(hdc);
              }
              break;
              }
        }
开发者ID:sinc,项目名称:DeviceHandler,代码行数:33,代码来源:ChartPanel.cs

示例8: ProcessEMF

 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();
         }
     }
 }
开发者ID:NelsonSantos,项目名称:fyiReporting-Android,代码行数:26,代码来源:EMF.cs

示例9: Convert

        public static Metafile Convert(
            string htmlSnippet, 
            float leftBorder = 0, 
            float topBorder = 0, 
            float rightBorder = 0, 
            float bottomBorder = 0)
        {
            Metafile image;
            IntPtr dib;
            IntPtr memoryHdc = Win32Utils.CreateMemoryHdc(IntPtr.Zero, 1, 1, out dib);
            try
            {
                image = new Metafile(memoryHdc, EmfType.EmfPlusDual, "..");

                using (Graphics g = Graphics.FromImage(image))
                {
                    SizeF size = HtmlRender.Measure(g, htmlSnippet);
                    
                    g.FillRectangle(
                        Brushes.White, 
                        leftBorder * -1, 
                        topBorder * -1, 
                        size.Width + leftBorder + rightBorder, 
                        size.Height + topBorder + bottomBorder);

                    SizeF sizeF = HtmlRender.Render(g, htmlSnippet);
                }
            }
            finally
            {
                Win32Utils.ReleaseMemoryHdc(memoryHdc, dib);
            }
            return image;
        }
开发者ID:jeromerg,项目名称:NDocUtil,代码行数:34,代码来源:HtmlToMetafileUtil.cs

示例10: GetImageFromParams

        private static Image GetImageFromParams(object pict, IntPtr handle, int pictype, IntPtr paletteHandle, int width,
		                                        int height)
        {
            switch (pictype)
            {
                case -1:
                    return null;

                case 0:
                    return null;

                case 1:
                    return Image.FromHbitmap(handle, paletteHandle);

                case 2:
                    {
                        var wmfHeader = new WmfPlaceableFileHeader();
                        wmfHeader.BboxRight = (short) width;
                        wmfHeader.BboxBottom = (short) height;
                        var metafile = new Metafile(handle, wmfHeader, false);
                        return (Image) RuntimeHelpers.GetObjectValue(metafile.Clone());
                    }
                case 4:
                    {
                        var metafile2 = new Metafile(handle, false);
                        return (Image) RuntimeHelpers.GetObjectValue(metafile2.Clone());
                    }
            }
            throw new Exception("AXUnknownImage");
        }
开发者ID:baens,项目名称:Esri2011,代码行数:30,代码来源:BitmapUtil.cs

示例11: SaveClipboardEmf

        private static void SaveClipboardEmf(Stream stream, ImageFormat format)
        {
            OpenClipboard();

            try
            {
                if (!IsClipboardFormatAvailable(CF_ENHMETAFILE))
                {
                    Failed("No enhanced metafile data available.");
                }

                IntPtr ptr = GetClipboardData(CF_ENHMETAFILE);

                if (ptr == IntPtr.Zero)
                {
                    Failed("Unable to retrieve data from clipboard even through Clipboard previously indicated data exists.");
                }

                var metafile = new Metafile(ptr, true);
                metafile.Save(stream, format);
            }
            finally
            {
                // "An application should call the CloseClipboard function after every successful call to OpenClipboard."
                //   -- http://msdn.microsoft.com/en-us/library/windows/desktop/ms649048(v=vs.85).aspx
                CloseClipboard();
            }
        }
开发者ID:eHanlin,项目名称:Hanlin.Common,代码行数:28,代码来源:ClipboardHelper.cs

示例12: DrawSvg

        protected override Image DrawSvg(SvgDocument svgDoc)
        {
            // GDI+
            Metafile metafile;
            using (var stream = new MemoryStream())
            using (var img = new Bitmap((int)svgDoc.Width.Value, (int)svgDoc.Height.Value)) // Not necessary if you use Control.CreateGraphics().
            using (Graphics ctrlGraphics = Graphics.FromImage(img)) // Control.CreateGraphics()
            {
                IntPtr handle = ctrlGraphics.GetHdc();

                var rect = new RectangleF(0, 0, svgDoc.Width, svgDoc.Height);
                metafile = new Metafile(stream,
                    handle,
                    rect,
                    MetafileFrameUnit.Pixel,
                    EmfType.EmfPlusOnly);

                using (Graphics ig = Graphics.FromImage(metafile))
                {
                    svgDoc.Draw(ig);
                }

                ctrlGraphics.ReleaseHdc(handle);
            }

            return metafile;
        }
开发者ID:dteunkenstt,项目名称:SVG,代码行数:27,代码来源:MetafileRenderingTest.cs

示例13: LoadWMFFile

        // Загрузка рисунка из файла
        private void LoadWMFFile(String name)
        {
            // Создание рисунка из файла
            this.wmfImage = new Metafile(name);

            // Вызов метода перерисовки формы
            this.Invalidate();
        }
开发者ID:xs2ranjeet,项目名称:13ns9-1spr,代码行数:9,代码来源:Form1.cs

示例14: PrintPage

        private void PrintPage(object sender, PrintPageEventArgs ev)
        {
            Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);
            ev.Graphics.DrawImage(pageImage, ev.PageBounds);

            m_currentPageIndex++;
            ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
        }
开发者ID:mahuidong,项目名称:c-1200-II,代码行数:8,代码来源:Form1.cs

示例15: MakeMetafileStream

        /// <summary>
        /// 
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="shapes"></param>
        /// <param name="properties"></param>
        /// <param name="ic"></param>
        /// <returns></returns>
        public MemoryStream MakeMetafileStream(
            Bitmap bitmap,
            IEnumerable<BaseShape> shapes,
            ImmutableArray<ShapeProperty> properties,
            IImageCache ic)
        {
            var g = default(Graphics);
            var mf = default(Metafile);
            var ms = new MemoryStream();

            try
            {
                using (g = Graphics.FromImage(bitmap))
                {
                    var hdc = g.GetHdc();
                    mf = new Metafile(ms, hdc);
                    g.ReleaseHdc(hdc);
                }

                using (g = Graphics.FromImage(mf))
                {
                    var r = new EmfRenderer(72.0 / 96.0);
                    r.State.ImageCache = ic;

                    g.SmoothingMode = SmoothingMode.HighQuality;
                    g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                    g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                    g.CompositingQuality = CompositingQuality.HighQuality;
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                    g.PageUnit = GraphicsUnit.Display;

                    if (shapes != null)
                    {
                        foreach (var shape in shapes)
                        {
                            shape.Draw(g, r, 0, 0, properties, null);
                        }
                    }

                    r.ClearCache(isZooming: false);
                }
            }
            finally
            {
                if (g != null)
                {
                    g.Dispose();
                }

                if (mf != null)
                {
                    mf.Dispose();
                }
            }
            return ms;
        }
开发者ID:gitter-badger,项目名称:Test2d,代码行数:65,代码来源:EmfWriter.cs


注:本文中的System.Drawing.Imaging.Metafile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。