2009-03-24 6 views
2

MapXtremeフォーラムにこの質問を投稿しましたが、誰も質問に答えなかったので、ここで誰かがこの製品に関するいくつかの経験を持っていることを期待しています。 MapInfoの)MapXtreme StylesからBitmapを作るにはどうすればいいですか?

を作り、私は二つの方法を試してみましたが、私が得るすべては暗いX.ここ

と灰色のビットマップである私はのMapXtremeデスクトップアプリに取り組んでいますし、私達は私達の機能のスタイル

のビットマップを必要とします両方の方法がコードにありますが、1つはコメントアウトされています:

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

答えて

0

答えを待った後に - と無数の他の方法を試す - すべて無駄に、私は「手で」それをすべて行う上で決めたつまり私は単にスタイルオブジェクトに見えるの色を取得しますレイヤータイプ(線またはポリゴン)に適したビットマップを描画します。

これはすべてのケースを扱いませんし、ラインスタイルやインテリアカラーを処理しませんが、今のところ私の目的に役立ちます。

ここにはそのコードがあります。

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

最初のコードはすでにほとんど機能しています。私はちょうどそれを修正するためにそれを微調整した。 私はそれにsimplevectorpointスタイルを含む複合スタイルをテストしました。

/// <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; 
    } 
関連する問題