private static byte[] ToMetafile(this Identicon icon) { using (var desktopGraphics = Graphics.FromHwnd(IntPtr.Zero)) { var hdc = desktopGraphics.GetHdc(); try { using (var memoryStream = new MemoryStream()) { using (var img = new Metafile(memoryStream, hdc, new System.Drawing.Rectangle(0, 0, icon.Size, icon.Size), MetafileFrameUnit.Pixel, EmfType.EmfPlusDual)) { using (var graphics = Graphics.FromImage(img)) { icon.Draw(graphics); } } return(memoryStream.ToArray()); } } finally { desktopGraphics.ReleaseHdc(hdc); } } }
private static string GenerateSvg(this Identicon icon, bool fragment) { var renderer = new SvgRenderer(icon.Size, icon.Size); icon.Draw(renderer); return(renderer.ToSvg(fragment)); }
/// <summary> /// Renders an <see cref="Identicon"/> as a WPF <see cref="Visual"/>. /// </summary> /// <param name="icon">The identicon to convert to a <see cref="Visual"/>.</param> public static Visual ToVisual(this Identicon icon) { var visual = new DrawingVisual(); using (var context = visual.RenderOpen()) { icon.Draw(context); } return(visual); }
private static byte[] GeneratePng(this Identicon icon) { var renderer = new PngRenderer(icon.Size, icon.Size); icon.Draw(renderer); using (var memoryStream = new MemoryStream()) { renderer.SavePng(memoryStream); return(memoryStream.ToArray()); } }
/// <summary> /// Renders an <see cref="Identicon"/> as a WPF <see cref="Visual"/>. /// </summary> /// <param name="icon">The identicon to convert to a <see cref="Visual"/>.</param> public static Visual ToVisual(this Identicon icon) { var visual = new DrawingVisual(); using (var context = visual.RenderOpen()) { var iconBounds = icon.GetIconBounds(); icon.Draw(context, iconBounds); } return(visual); }
/// <summary> /// Renders an <see cref="Identicon"/> to a GDI <see cref="Bitmap"/>. /// </summary> /// <param name="icon">The identicon to render.</param> /// <remarks> /// The caller should dispose the returned <see cref="Bitmap"/> once it does not /// need it anymore. /// </remarks> public static Bitmap ToBitmap(this Identicon icon) { var img = new Bitmap(icon.Size, icon.Size); try { using (var g = Graphics.FromImage(img)) { icon.Draw(g); } return(img); } catch { img.Dispose(); throw; } }
/// <summary> /// Draws an <see cref="Identicon"/> in a specified GDI drawing context at position (0, 0). /// </summary> /// <param name="icon">The identicon to draw.</param> /// <param name="g">Drawing context in which the icon will be rendered.</param> public static void Draw(this Identicon icon, Graphics g) { var renderer = new GdiRenderer(g); icon.Draw(renderer); }
/// <summary> /// Draws an <see cref="Identicon"/> in a specified GDI drawing context. /// </summary> /// <param name="icon">The identicon to draw.</param> /// <param name="g">Drawing context in which the icon will be rendered.</param> /// <param name="rect">The bounds of the rendered icon, including padding.</param> public static void Draw(this Identicon icon, Graphics g, System.Drawing.Rectangle rect) { icon.Draw(g, rect.ToJdenticon()); }
/// <summary> /// Draws an <see cref="Identicon"/> in a specified GDI drawing context. /// </summary> /// <param name="icon">The identicon to draw.</param> /// <param name="g">Drawing context in which the icon will be rendered.</param> /// <param name="rect">The bounds of the rendered icon, including padding.</param> public static void Draw(this Identicon icon, Graphics g, Rendering.Rectangle rect) { var renderer = new GdiRenderer(g); icon.Draw(renderer, rect); }
/// <summary> /// Draws an <see cref="Identicon"/> in a specified WPF drawing context at position (0, 0). /// </summary> /// <param name="icon">The identicon to draw.</param> /// <param name="drawingContext">Drawing context in which the icon will be rendered.</param> public static void Draw(this Identicon icon, DrawingContext drawingContext) { var renderer = new WpfRenderer(drawingContext); icon.Draw(renderer); }
/// <summary> /// Draws an <see cref="Identicon"/> in a specified WPF drawing context. /// </summary> /// <param name="icon">The identicon to draw.</param> /// <param name="drawingContext">Drawing context in which the icon will be rendered.</param> /// <param name="rect">The bounds of the rendered icon, including padding.</param> public static void Draw(this Identicon icon, DrawingContext drawingContext, System.Windows.Rect rect) { icon.Draw(drawingContext, rect.ToJdenticon()); }
/// <summary> /// Draws an <see cref="Identicon"/> in a specified WPF drawing context. /// </summary> /// <param name="icon">The identicon to draw.</param> /// <param name="drawingContext">Drawing context in which the icon will be rendered.</param> /// <param name="rect">The bounds of the rendered icon, including padding.</param> public static void Draw(this Identicon icon, DrawingContext drawingContext, Rendering.Rectangle rect) { var renderer = new WpfRenderer(drawingContext); icon.Draw(renderer, rect); }