This document is archived and information here might be outdated.  Recommended version.


Create Marker Symbol From MOLE Cached Graphic Snippet (ArcObjects .NET 10.4 SDK)
ArcObjects Library Reference

Create Marker Symbol From MOLE Cached Graphic Snippet

Exports a MOLE Cached Graphic to an IPictureMarkerSymbol.

[C#]
///<summary>Exports a MOLE Cached Graphic to an IPictureMarkerSymbol.</summary>
///  
///<param name="cachedGraphic">An ICachedGraphic interface.</param>
///<param name="display">An IDisplay interface. (ActiveView.ScreenDisplay if possible)</param>
///<param name="color">An IColor interface that is the transparent color for the exported image.</param>
///<param name="exportSize">A System.Int32 that is the pixel heigth/width size of the exported image. Example: 256</param>
///<param name="symbolSize">A System.Double that is the MarkerSymbol size. Example: 72</param>
///   
///<returns>An IMarkerSymbol interface if successful, Nothing otherwise</returns>
///   
///<remarks>
///Call this method to export a MOLE Cached Graphic to an IPictureMarkerSymbol
///This IPictureMarkerSymbol can then be used as any other MarkerSymbol would
///</remarks>
public ESRI.ArcGIS.Display.IMarkerSymbol CreateMarkerSymbolFromMOLECachedGraphic(ESRI.ArcGIS.DefenseSolutions.ICachedGraphic cachedGraphic, ESRI.ArcGIS.Display.IDisplay display, ESRI.ArcGIS.Display.IColor color, System.Int32 exportSize, System.Double symbolSize)
{
  // Is it is a valid graphic
  if (cachedGraphic == null)
  {
    System.Diagnostics.Trace.WriteLine("Null Graphic provided");
    return null; // i.e. fail
  }

  // Create a picture marker symbol from the IPictureMarkerSymbol interface
  ESRI.ArcGIS.Display.IPictureMarkerSymbol pictureMarkerSymbol=new ESRI.ArcGIS.Display.PictureMarkerSymbolClass();

  ESRI.ArcGIS.DefenseSolutions.ICreateBitmap createBitmap=cachedGraphic as ESRI.ArcGIS.DefenseSolutions.ICreateBitmap; // Dynamic Cast
  ESRI.ArcGIS.Display.IColor bitmapColor=color as ESRI.ArcGIS.Display.IColor; // Dynamic Cast
  stdole.IPictureDisp picture=createBitmap.DrawToPicture(display, exportSize, exportSize, 1.2, bitmapColor);

  pictureMarkerSymbol.Picture=picture;

  // Set the picture marker transparency color and symbol�s size (in points)
  pictureMarkerSymbol.BitmapTransparencyColor=color;
  pictureMarkerSymbol.Size=symbolSize;

  // Return the picture marker�s IMarkerSymbol reference
  return pictureMarkerSymbol as ESRI.ArcGIS.Display.IMarkerSymbol; // Dynamic Cast
}
[Visual Basic .NET]
'''<summary>Exports a MOLE Cached Graphic to an IPictureMarkerSymbol.</summary>
'''  
'''<param name="cachedGraphic">An ICachedGraphic interface.</param>
'''<param name="display">An IDisplay interface. (ActiveView.ScreenDisplay if possible)</param>
'''<param name="color">An IColor interface that is the transparent color for the exported image.</param>
'''<param name="exportSize">A System.Int32 that is the pixel heigth/width size of the exported image. Example: 256</param>
'''<param name="symbolSize">A System.Double that is the MarkerSymbol size. Example: 72</param>
'''   
'''<returns>An IMarkerSymbol interface if successful, Nothing otherwise</returns>
'''   
'''<remarks>
'''Call this method to export a MOLE Cached Graphic to an IPictureMarkerSymbol
'''This IPictureMarkerSymbol can then be used as any other MarkerSymbol would
'''</remarks>
Public Function CreateMarkerSymbolFromMOLECachedGraphic(ByVal cachedGraphic As ESRI.ArcGIS.DefenseSolutions.ICachedGraphic, ByVal display As ESRI.ArcGIS.Display.IDisplay, ByVal color As ESRI.ArcGIS.Display.IColor, ByVal exportSize As System.Int32, ByVal symbolSize As System.Double) As ESRI.ArcGIS.Display.IMarkerSymbol

  ' Is it is a valid graphic
  If cachedGraphic Is Nothing Then
    System.Diagnostics.Trace.WriteLine("Nothing Graphic provided")
    Return Nothing
  End If

  ' Create a picture marker symbol from the IPictureMarkerSymbol interface
  Dim pictureMarkerSymbol As ESRI.ArcGIS.Display.IPictureMarkerSymbol=New ESRI.ArcGIS.Display.PictureMarkerSymbolClass

  Dim createBitmap As ESRI.ArcGIS.DefenseSolutions.ICreateBitmap=CType(cachedGraphic, ESRI.ArcGIS.DefenseSolutions.ICreateBitmap) ' Explicit Cast
  Dim bitmapColor As ESRI.ArcGIS.Display.IColor=color

  ' Set the picture marker transparency color and symbol�s size (in points)
  Dim pictureDisp As stdole.IPictureDisp=createBitmap.DrawToPicture(display, exportSize, exportSize, 1.2, bitmapColor)
  pictureMarkerSymbol.Picture=pictureDisp
  pictureMarkerSymbol.BitmapTransparencyColor=color
  pictureMarkerSymbol.Size=symbolSize

  Dim markerSymbol As ESRI.ArcGIS.Display.IMarkerSymbol=pictureMarkerSymbol

  'Return the picture marker�s IMarkerSymbol reference
  Return markerSymbol

End Function

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.DefenseSolutions
  • ESRI.ArcGIS.Display
  • ESRI.ArcGIS.System
  • stdole