示例#1
0
        static void CreateBitmap(int size, IconRenderer iconRenderer, string fileName, double cornerRadius = 0)
        {
            using (var bm = new Bitmap(size, size, PixelFormat.Format32bppArgb))
            {
                using (var g = Graphics.FromImage(bm))
                {
                    g.TextRenderingHint  = TextRenderingHint.AntiAliasGridFit;
                    g.SmoothingMode      = SmoothingMode.AntiAlias;
                    g.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                    g.PixelOffsetMode    = PixelOffsetMode.HighQuality;
                    g.CompositingQuality = CompositingQuality.HighQuality;
                    g.CompositingMode    = CompositingMode.SourceOver;
                    using (var rc = new GraphicsRenderContext(g)
                    {
                        RendersToScreen = false
                    })
                    {
                        g.Clear(Color.Transparent);

                        if (cornerRadius > 0)
                        {
                            // TODO: no antialiasing on the clipping path?
                            var path = GetRoundedRect(new RectangleF(0, 0, size, size), (float)cornerRadius);
                            g.SetClip(path, CombineMode.Replace);
                        }

                        iconRenderer.Render(rc, size);
                    }

                    bm.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
                }
            }
        }
示例#2
0
 static void CreateSvg(int size, IconRenderer iconRenderer, string fileName)
 {
     using (var bm = new Bitmap(size, size))
     {
         using (var grx = new GraphicsRenderContext(Graphics.FromImage(bm)))
         {
             using (var s = File.Create(fileName))
             {
                 using (var rc = new SvgRenderContext(s, size, size, true, grx, OxyColors.Transparent))
                 {
                     iconRenderer.Render(rc, size);
                 }
             }
         }
     }
 }
示例#3
0
 static void CreateSvg(int size, IconRenderer iconRenderer, string fileName)
 {
     using (var bm = new Bitmap(size, size))
     {
         using (var grx = new GraphicsRenderContext(Graphics.FromImage(bm)))
         {
             using (var s = File.Create(fileName))
             {
                 using (var rc = new SvgRenderContext(s, size, size, true, grx, OxyColors.Transparent))
                 {
                     iconRenderer.Render(rc, size);
                 }
             }
         }
     }
 }
示例#4
0
        static void CreateBitmap(int size, IconRenderer iconRenderer, string fileName, double cornerRadius = 0)
        {
            using (var bm = new Bitmap(size, size, PixelFormat.Format32bppArgb))
            {
                using (var g = Graphics.FromImage(bm))
                {
                    g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                    g.CompositingQuality = CompositingQuality.HighQuality;
                    g.CompositingMode = CompositingMode.SourceOver;
                    using (var rc = new GraphicsRenderContext(g) { RendersToScreen = false })
                    {
                        g.Clear(Color.Transparent);

                        if (cornerRadius > 0)
                        {
                            // TODO: no antialiasing on the clipping path?
                            var path = GetRoundedRect(new RectangleF(0, 0, size, size), (float)cornerRadius);
                            g.SetClip(path, CombineMode.Replace);
                        }

                        iconRenderer.Render(rc, size);
                    }

                    bm.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
                }
            }
        }