ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / ISymbolFactory Interface / GenerateImage Method
Example

In This Topic
    GenerateImage Method (ISymbolFactory)
    In This Topic
    Generates an image for point sybmols.
    Syntax

    Parameters

    pointSymbol
    imageFormat
    scaleFactor
    centerAnchorPoint
    dpi
    width
    height
    backgroundColor

    Return Value

    Example
    Convert Point Symbol to SVG
    {
      var mem_strm = await QueuedTask.Run(() =>
      {
        //Create a point symbol
        var pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(
          ColorFactory.Instance.RedRGB, 24, SimpleMarkerStyle.RoundedSquare);
    
        //Generate image returns a stream
        return SymbolFactory.Instance.GenerateImage(
          pointSymbol, OutputImageFormat.SVG, 2.0, true, 300, 100, 100,
          ColorFactory.Instance.WhiteRGB);
      });
    
      //Set the memory stream position to the beginning
      mem_strm.Seek(0, SeekOrigin.Begin);
    
      //File path and name for saving the SVG file
      var fileName = "RoundedSquareSymbol.svg";
      string path_svg = System.IO.Path.Combine(System.IO.Path.GetTempPath() + fileName);
    
      //Write the memory stream to the file
      System.IO.File.WriteAllBytes(path_svg, mem_strm.ToArray());
    
      //////////////////////////////////////////////
      //Note: to convert SVG to image format, use a 3rd party
      //e.g. Aspose.SVG for .NET, for example convert SVG to PNG
      //using (var svg_doc = new Aspose.Svg.SVGDocument(path_svg))
      //{
      //  string path_png = Path.Combine(Path.GetTempPath() + "RoundedSquareSymbol.png");
      //  using (var img_png = new Aspose.Svg.Rendering.Image.ImageDevice(
      //    new ImageRenderingOptions(ImageFormat.Png), path_png))
      //  {
      //    svg_doc.RenderTo(img_png);
      //  }
      //  //also: https://docs.aspose.com/imaging/net/convert-svg-to-png/
      //}
    }
    Convert Point Symbol to PNG
    {
      var mem_strm = await QueuedTask.Run(() =>
      {
        //Create a point symbol
        var pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(
          ColorFactory.Instance.RedRGB, 24, SimpleMarkerStyle.RoundedSquare);
    
        //Generate image returns a stream
        return SymbolFactory.Instance.GenerateImage(
          pointSymbol, OutputImageFormat.PNG, 2.0, true, 300, 100, 100,
          ColorFactory.Instance.WhiteRGB);
      });
    
      //Set the memory stream position to the beginning
      mem_strm.Seek(0, SeekOrigin.Begin);
    
      //Write the stream to a bit map
      var bitmapImage = new System.Windows.Media.Imaging.BitmapImage();
    
      bitmapImage.BeginInit();
      bitmapImage.StreamSource = mem_strm;
      bitmapImage.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
      bitmapImage.EndInit();
      bitmapImage.Freeze();
    
      //Write the bit map out to a file
      //File path and name for saving the PNG file
      var fileName = "RoundedSquareSymbol.png";
      string path_png = System.IO.Path.Combine(System.IO.Path.GetTempPath() + fileName);
    
      BitmapEncoder encoder = new PngBitmapEncoder();
      encoder.Frames.Add(BitmapFrame.Create(bitmapImage));
    
      using (var fileStream = new System.IO.FileStream(
        path_png, System.IO.FileMode.Create))
      {
        encoder.Save(fileStream);
      }
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.4 or higher.
    See Also