RenderSvgz.cs
  1. //
  2. // This code is part of Document Solutions for Imaging demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.IO;
  7. using System.Drawing;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Numerics;
  11. using GrapeCity.Documents.Drawing;
  12. using GrapeCity.Documents.Text;
  13. using GrapeCity.Documents.Imaging;
  14. using GrapeCity.Documents.Svg;
  15. using GCTEXT = GrapeCity.Documents.Text;
  16. using GCDRAW = GrapeCity.Documents.Drawing;
  17. using DsImagingWeb.Demos.Common;
  18.  
  19. namespace DsImagingWeb.Demos
  20. {
  21. // This sample shows how to render an SVGZ (compressed SVG) image.
  22. // The SVG art used in this sample is from freesvg.org.
  23. public class RenderSvgz
  24. {
  25. public GcBitmap GenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null)
  26. {
  27. var svgPath = Path.Combine("Resources", "SvgMisc", "Smiling-Girl.svgz");
  28. using var svg = GcSvgDocument.FromSvgz(File.ReadAllBytes(svgPath));
  29.  
  30. // Render the SVG image and a border around it:
  31. var bmp = new GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi);
  32. using var g = bmp.CreateGraphics(Color.White);
  33. var pt = new PointF(dpi, dpi);
  34. g.DrawSvg(svg, pt);
  35. var sz = svg.GetIntrinsicSize(SvgLengthUnits.Pixels);
  36. g.DrawRectangle(new RectangleF(pt, sz), Color.MediumPurple);
  37.  
  38. // Done:
  39. return bmp;
  40. }
  41. }
  42. }
  43.