• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Imaging.Metafile类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: MetafileToString

		/*
		 * MetafileToString
		 */

		/// <summary>
		/// </summary>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="metafileToConvert"/> is <see langword="null"/>.
		/// </exception>
		public static string MetafileToString(Metafile metafileToConvert)
		{
			if (metafileToConvert == null)
			{
				throw new ArgumentNullException("metafileToConvert");
			}

			byte[] buffer = NuGenMetafileConverter.MetafileToBytes(metafileToConvert);
			return Convert.ToBase64String(buffer);
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:19,代码来源:NuGenMetafileConverter.cs


示例17: EMFRenderer

 public EMFRenderer(int width, int height)
 {
     Bitmap bmp = new Bitmap(width, height);
     m_graphics = Graphics.FromImage(bmp);
     m_stream = new MemoryStream();
     m_metafile = new Metafile(m_graphics.GetHdc(), new RectangleF(0, 0, width, height), MetafileFrameUnit.Pixel);
     m_graphics.ReleaseHdc();
     m_graphics.Dispose();
     bmp.Dispose();
     m_graphics = Graphics.FromImage(m_metafile);
 }
开发者ID:csuffyy,项目名称:circuitdiagram,代码行数:11,代码来源:EMFRenderer.cs


示例18: skolaUppdaterad

 public override void skolaUppdaterad()
 {
     if ( _mf!=null )
         _mf.Dispose();
     string strMF = Global.Skola.HomePathCombine( "!fotoorder.emf" );
     if ( System.IO.File.Exists(strMF) )
         _mf = new Metafile( strMF );
     else
         _mf = null;
     resize2(this.ClientSize);
     this.Invalidate();
 }
开发者ID:danbystrom,项目名称:VisionQuest,代码行数:12,代码来源:frmOrder.cs


示例19: CreateInternalMetafile

		private void CreateInternalMetafile(EmfType type)
		{
			//Create a temporary bitmap to get an HDC
			Graphics graphics = Component.Instance.CreateGraphics();
			IntPtr hDC = graphics.GetHdc();

			//Create metafile based on type and get graphics handle
			mMetafile = new System.Drawing.Imaging.Metafile(hDC, type);
			graphics.ReleaseHdc(hDC);

			graphics.Dispose();
		}
开发者ID:savagemat,项目名称:arcgis-diagrammer,代码行数:12,代码来源:Metafile.cs


示例20: SaveMetafile

        public static void SaveMetafile(Metafile mf, Stream stream)
        {
            IntPtr henh = mf.GetHenhmetafile ();
            int size = GetEnhMetaFileBits (henh, 0, null);

            byte[] buffer = new byte[size];

            if (GetEnhMetaFileBits (henh, size, buffer) <= 0)
                throw new SystemException ("GetEnhMetaFileBits");

            stream.Write (buffer, 0, buffer.Length);
            stream.Flush ();
        }
开发者ID:metamolecular,项目名称:indigo,代码行数:13,代码来源:IndigoRenderer.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Imaging.PropertyItem类代码示例发布时间:2022-05-26
下一篇:
C# Imaging.ImageFormat类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap