2009-03-24 2 views
2

Ich habe diese Frage auf dem MapXtreme Forum gepostet, aber da niemand jemals Fragen beantwortet, hoffe ich, dass jemand hier Erfahrung mit diesem Produkt hat (mapxtreme ist ein GIS SDK von den Leuten, die machen MapInfo)Wie kann ich ein Bitmap von MapXtreme Styles erstellen?

ich auf einer MapXtreme Desktop App arbeite und wir brauchen Bitmaps unserer Features Arten

ich zwei Möglichkeiten versucht, aber alles, was ich bekommen ist ein grauer Bitmap mit einem dunklen X.

hier ist der Code, den ich beide Möglichkeiten im Code verwendet habe, aber einer ist auskommentiert:

public static Bitmap GetStyleBitmap(Style style) 
    { 
     var bm = new Bitmap(16, 16, System.Drawing.Imaging.PixelFormat.Format32bppArgb); 
     var rect = new System.Drawing.Rectangle(0, 0, 16, 16); 
     var ss = new StyleSample(); 
     ss.Bounds = rect; 
     if (style is CompositeStyle) 
     { 
      ss.ApplyAreaStyle(((CompositeStyle)style).AreaStyle); 
      ss.ApplyLineStyle(((CompositeStyle)style).LineStyle); 
     } 
     if (style is AreaStyle) 
     { 
      ss.ApplyAreaStyle((AreaStyle)style); 
     } 
     if (style is SimpleLineStyle) 
     { 
      ss.ApplyLineStyle((SimpleLineStyle)style); 
     } 

     //using MapExport 
     var me = new MapExport(ss.Map); 
     var image = me.Export(); 
     return new Bitmap(image); 

     //using StyleSample.DrawToBitmap 
     //ss.DrawToBitmap(bm, rect); 
     //return bm; 
    } 

TIA

Antwort

0

Nachdem eine Antwort abzuwarten - und unzählige andere Wege versuchen - alles ohne Erfolg, entschied ich alles ‚von Hand‘ auf dem Tun also ich schaue im Stil Objekt einfach erhält die Farbe und zeichnen Sie eine Bitmap, die für den Layer-Typ (Linie oder Polygon) geeignet ist.

Es behandelt nicht jeden Fall und behandelt auch nicht Linienarten oder Innenfarben, aber es dient meinen Zwecken für jetzt.

Hier ist der Code, der es tut.

public static Bitmap GetStyleBitmap(FeatureLayer fl) 
    { 
     Feature f = GetFirstFeature(fl); 
     if (f == null) return null; 

     var style = f.Style; 
     Color c; 
     var bm = new Bitmap(16, 16, System.Drawing.Imaging.PixelFormat.Format32bppArgb); 
     PointF[] poly = new PointF[] 
     { 
      new PointF(2,5), 
      new PointF(5,2), 
      new PointF(14,7), 
      new PointF(14,14), 
      new PointF(2,14), 
      new PointF(2,4) 
     }; 

     SimpleLineStyle line = null; 
     if (style is CompositeStyle) 
      line = ((CompositeStyle)style).AreaStyle.Border as SimpleLineStyle; 
     if (style is AreaStyle) 
      line = ((AreaStyle)style).Border as SimpleLineStyle; 

     if (line != null) 
     { 
      c = line.Color; 

      using (var gr = Graphics.FromImage(bm)) 
      { 
       gr.DrawPolygon(new Pen(c, 2), poly); 
      } 
      return bm; 
     } 

     line = style as SimpleLineStyle; 

     if (line != null) 
     { 
      c = line.Color; 

      using (var gr = Graphics.FromImage(bm)) 
      { 
       gr.DrawLine(new Pen(c, 2), new PointF(2,2), new PointF(14,14)); 
      } 
     } 
     return bm; 
    } 
0

Der erste Code bereits fast funktioniert. Ich habe es nur ein bisschen verbessert, um es zu beheben. Ich habe es für einen zusammengesetzten Stil getestet, der einen simplevectorpointstyle enthält.

/// <summary> 
    /// Creates an icon for the specified style. 
    /// </summary> 
    /// <param name="style">The style.</param> 
    /// <returns></returns> 
    private static Bitmap CreateStyleIcon(Style style) 
    { 
     const int iconSize = 16; //the size of the icon 
     System.Drawing.Rectangle iconArea = new System.Drawing.Rectangle(0, 0, iconSize, iconSize); //a rectangle area for the icon 
     StyleSample ss = new StyleSample { Bounds = iconArea }; 
     if (style is CompositeStyle) 
     { 
      CompositeStyle compsiteStyle = style as CompositeStyle; 
      if (compsiteStyle.AreaStyle != null) //do we have an area style? 
      { 
       ss.ApplyAreaStyle(compsiteStyle.AreaStyle); 
      } 
      if (compsiteStyle.LineStyle != null) //do we have an LineStyle style? 
      { 
       ss.ApplyLineStyle(compsiteStyle.LineStyle); 
      } 
      if (compsiteStyle.SymbolStyle != null) //do we have an SymbolStyle style? 
      { 
       ss.ApplySymbol(compsiteStyle.SymbolStyle); 
      } 
     } 
     if (style is AreaStyle) 
     { 
      ss.ApplyAreaStyle((AreaStyle)style); 
     } 
     if (style is BaseLineStyle) 
     { 
      ss.ApplyLineStyle((BaseLineStyle)style); 
     } 

     //draw the bitmap 
     Bitmap iconBitmap = new Bitmap(iconSize, iconSize, System.Drawing.Imaging.PixelFormat.Format32bppArgb);//the bitmap to draw the icon to 
     ss.DrawToBitmap(iconBitmap, iconArea); 
     return iconBitmap; 
    }