stdole.IPictureDisp


ピクチャマーカにセットされた画像を保存する適当なコード
stdole.IPictureDispは調べたら色々出てくるのでGoogle先生に聞くとよい。
あとMultiのPictureは1枚にDrawした方が良い。

using System;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.Display;
using System.Runtime.InteropServices;
string mxdPath = @"c:\\xxx.mxd";
string saveDir = @"C:\xxx";

using (ComReleaser com = new ComReleaser())
{
IMapDocument mapDoc = new MapDocumentClass();
com.ManageLifetime(mapDoc);

mapDoc.Open(mxdPath);
IMap map = mapDoc.get_Map(0);
com.ManageLifetime(map);

mapDoc.Close();

IGeoFeatureLayer geoLayer = map.get_Layer(0) as IGeoFeatureLayer;
IUniqueValueRenderer render = geoLayer.Renderer as IUniqueValueRenderer;

for (int i = 0; i < render.ValueCount; i++)
{
  var val = render.get_Value(i);
  var sym = render.get_Symbol(val);

  if (sym is IMultiLayerMarkerSymbol)
  {
    var mLayer = (IMultiLayerMarkerSymbol)sym;
    for (int linx = 0; linx < mLayer.LayerCount; linx++)
    {
      var lsym = (ISymbol)mLayer.get_Layer(linx);
      savePict(lsym, saveDir, val + linx.ToString());
    }
  }
  else
    savePict(sym, saveDir, val);

}//end loop
}//end com
private static void savePict(ISymbol sym, string saveDir, string val)
{

  if (!(sym is ESRI.ArcGIS.Display.IPictureMarkerSymbol))
    return;
  IPictureMarkerSymbol pictSymbol = (IPictureMarkerSymbol)sym;
  var olePict = pictSymbol.Picture;

  IntPtr paletteHandle = new IntPtr(olePict.hPal);
  IntPtr bitmapHandle = new IntPtr(olePict.Handle);
  using (var image = System.Drawing.Image.FromHbitmap(bitmapHandle, paletteHandle))
  {
    var saveFile = System.IO.Path.Combine(saveDir, val) + ".png";
    image.Save(saveFile, System.Drawing.Imaging.ImageFormat.Png);
  }
  Marshal.FinalReleaseComObject(olePict);
  Marshal.FinalReleaseComObject(pictSymbol);
}
カテゴリー: 開発 タグ: パーマリンク