ArcGIS 10.2 GDI+の仕様変更?


仮想環境で動かない?
何かミスか?実機の10.2では動いたが…。

シンプルディスプレイは一部エレメントやレイヤなんかで使えそうだがどう使ったものか。
面白い使い方はできそうだが。

using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geometry;
using System;
using System.Drawing;
using System.Drawing.Imaging;
using (ComReleaser com = new ComReleaser())
using (Bitmap bmp = new Bitmap(100, 100, PixelFormat.Format24bppRgb))
using (Graphics g = Graphics.FromImage(bmp))
{
  IPoint pt1 = new PointClass();
  com.ManageLifetime(pt1);
  IPoint pt2 = new PointClass();
  com.ManageLifetime(pt2);

  pt1.PutCoords(0, 0);
  pt2.PutCoords(100, 100);

  IPolyline line = new PolylineClass();
  com.ManageLifetime(line);
  line.FromPoint = pt1;
  line.ToPoint = pt2;

  IDisplay display = new SimpleDisplayClass();
  com.ManageLifetime(display);
  IDisplayTransformation tran = display.DisplayTransformation;
  com.ManageLifetime(tran);

  tran.Resolution = bmp.HorizontalResolution;

  IEnvelope env = ((IGeometry)line).Envelope;
  com.ManageLifetime(env);
  tran.Bounds = env;
  tran.VisibleBounds = env;

  tagRECT rect;
  rect.left = 0;
  rect.right = Convert.ToInt32(Math.Floor(env.Width));
  rect.top = 0;
  rect.bottom = Convert.ToInt32(Math.Floor(env.Height));

  tran.set_DeviceFrame(ref rect);

  g.Clear(Color.White);
  display.StartDrawing(g.GetHdc().ToInt32(), (short)esriScreenCache.esriNoScreenCache);

  ISimpleLineSymbol s = new SimpleLineSymbol();
  com.ManageLifetime(s);
  s.Style = esriSimpleLineStyle.esriSLSSolid;
  s.Width = 5;

  IRgbColor c = new RgbColorClass();
  com.ManageLifetime(c);
  c.Red = 255;
  c.Blue = 0;
  c.Green = 0;

  s.Color = c;

  display.SetSymbol((ISymbol)s);
  display.DrawPolyline((IPolyline)line);

  display.FinishDrawing();

  g.ReleaseHdc();
  g.Dispose();

  bmp.Save(@"c:\test.png", ImageFormat.Png);
}//end resource
カテゴリー: 開発 タグ: パーマリンク