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); } } }
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); } } } } }