MCPcopy Create free account
hub / github.com/MapServer/MapServer / Main

Method Main

mapscript/csharp/examples/drawmapDirect.cs:47–98  ·  view source on GitHub ↗
(string[] args)

Source from the content-addressed store, hash-verified

45 }
46
47 public static void Main(string[] args)
48 {
49 Console.WriteLine("");
50 if (args.Length < 2) usage();
51
52 mapObj map = new mapObj(args[0]);
53
54 Console.WriteLine("# Map layers " + map.numlayers + "; Map name = " + map.name);
55 for (int i = 0; i < map.numlayers; i++)
56 {
57 Console.WriteLine("Layer [" + i + "] name: " + map.getLayer(i).name);
58 }
59
60 try
61 {
62 // Create the output format
63 outputFormatObj of = new outputFormatObj("CAIRO/WINGDI", "cairowinGDI");
64 map.appendOutputFormat(of);
65 map.selectOutputFormat("cairowinGDI");
66
67 Bitmap mapImage = new Bitmap(map.width, map.height, PixelFormat.Format32bppRgb);
68
69 using (Graphics g = Graphics.FromImage(mapImage))
70 {
71 IntPtr hdc = g.GetHdc();
72 try
73 {
74 // Attach the device to the outputformat for drawing
75 of.attachDevice(hdc);
76 // Drawing directly to the GDI context
77 using (imageObj image = map.draw()) { };
78 }
79 finally
80 {
81 of.attachDevice(IntPtr.Zero);
82 g.ReleaseHdc(hdc);
83 }
84 }
85
86 mapImage.Save(args[1]);
87 }
88 catch (Exception ex)
89 {
90 Console.WriteLine( "\nMessage ---\n{0}", ex.Message );
91 Console.WriteLine(
92 "\nHelpLink ---\n{0}", ex.HelpLink );
93 Console.WriteLine( "\nSource ---\n{0}", ex.Source );
94 Console.WriteLine(
95 "\nStackTrace ---\n{0}", ex.StackTrace );
96 Console.WriteLine(
97 "\nTargetSite ---\n{0}", ex.TargetSite ); }
98 }
99}
100

Callers

nothing calls this directly

Calls 2

drawMethod · 0.80
usageFunction · 0.50

Tested by

no test coverage detected