I'm trying to export a legend that I have being displayed on a map as a separate bitmap file. I think I should be able to do it but all I get is a bitmap with nothing but black being displayed. Here is my code:
Public Sub tryExportLegend() Dim pMxDoc As IMxDocument pMxDoc = m_app.Document Dim PageLayout As IPageLayout = pMxDoc.PageLayout 'Locate the legend object Dim graphicsContainer As ESRI.ArcGIS.Carto.IGraphicsContainer = TryCast(PageLayout, ESRI.ArcGIS.Carto.IGraphicsContainer) graphicsContainer.Reset() Dim currentElement As IElement Dim storedGeom As IGeometry currentElement = graphicsContainer.Next While Not currentElement Is Nothing If TypeOf currentElement Is ESRI.ArcGIS.Carto.IMapSurroundFrame Then CType(currentElement, ESRI.ArcGIS.Carto.IMapSurroundFrame).MapSurround.Refresh() storedGeom = CType(currentElement.Geometry, IClone).Clone Exit While End If currentElement = graphicsContainer.Next End While 'Write the legend to a bitmap Dim myDisplay As IDisplay = New SimpleDisplay Dim outBitmap As Bitmap = New Bitmap(1000, 1000) Dim outGraphics As Graphics = Graphics.FromImage(outBitmap) myDisplay.StartDrawing(outGraphics.GetHdc, esriScreenCache.esriNoScreenCache) currentElement.Draw(myDisplay, Nothing) myDisplay.FinishDrawing() If File.Exists("c:\temp\legendOut.bmp") Then File.Delete("c:\temp\legendOut.bmp") End If outBitmap.Save("c:\temp\legendOut.bmp", System.Drawing.Imaging.ImageFormat.Bmp) End Sub