static void doc_PrintPage(object sender, PrintPageEventArgs e) { // Create the output format outputFormatObj of = new outputFormatObj("CAIRO/WINGDIPRINT", "cairowinGDIPrint"); map.appendOutputFormat(of); map.selectOutputFormat("cairowinGDIPrint"); map.resolution = e.Graphics.DpiX; Console.WriteLine("map resolution = " + map.resolution.ToString() + "DPI defresolution = " + map.defresolution.ToString() + " DPI"); // Calculating the desired image size to cover the entire area; map.width = Convert.ToInt32(e.PageBounds.Width * e.Graphics.DpiX / 100); map.height = Convert.ToInt32(e.PageBounds.Height * e.Graphics.DpiY / 100); Console.WriteLine("map size = " + map.width.ToString() + " * " + map.height.ToString() + " pixels"); IntPtr hdc = e.Graphics.GetHdc(); try { // Attach the device to the outputformat for drawing of.attachDevice(hdc); // Drawing directly to the GDI context using (imageObj image = map.draw()) { }; } finally { of.attachDevice(IntPtr.Zero); e.Graphics.ReleaseHdc(hdc); } e.HasMorePages = false; }
public static void Main(string[] args) { Console.WriteLine(""); if (args.Length < 2) { usage(); } mapObj map = new mapObj(args[0]); Console.WriteLine("# Map layers " + map.numlayers + "; Map name = " + map.name); for (int i = 0; i < map.numlayers; i++) { Console.WriteLine("Layer [" + i + "] name: " + map.getLayer(i).name); } try { // Create the output format outputFormatObj of = new outputFormatObj("CAIRO/WINGDI", "cairowinGDI"); map.appendOutputFormat(of); map.selectOutputFormat("cairowinGDI"); Bitmap mapImage = new Bitmap(map.width, map.height, PixelFormat.Format32bppRgb); using (Graphics g = Graphics.FromImage(mapImage)) { IntPtr hdc = g.GetHdc(); try { // Attach the device to the outputformat for drawing of.attachDevice(hdc); // Drawing directly to the GDI context using (imageObj image = map.draw()) { }; } finally { of.attachDevice(IntPtr.Zero); g.ReleaseHdc(hdc); } } mapImage.Save(args[1]); } catch (Exception ex) { Console.WriteLine("\nMessage ---\n{0}", ex.Message); Console.WriteLine( "\nHelpLink ---\n{0}", ex.HelpLink); Console.WriteLine("\nSource ---\n{0}", ex.Source); Console.WriteLine( "\nStackTrace ---\n{0}", ex.StackTrace); Console.WriteLine( "\nTargetSite ---\n{0}", ex.TargetSite); } }
public static void Main(string[] args) { Console.WriteLine(""); if (args.Length < 2) usage(); mapObj map = new mapObj(args[0]); Console.WriteLine("# Map layers " + map.numlayers + "; Map name = " + map.name); for (int i = 0; i < map.numlayers; i++) { Console.WriteLine("Layer [" + i + "] name: " + map.getLayer(i).name); } try { // Create the output format outputFormatObj of = new outputFormatObj("CAIRO/WINGDI", "cairowinGDI"); map.appendOutputFormat(of); map.selectOutputFormat("cairowinGDI"); Bitmap mapImage = new Bitmap(map.width, map.height, PixelFormat.Format32bppRgb); using (Graphics g = Graphics.FromImage(mapImage)) { IntPtr hdc = g.GetHdc(); try { // Attach the device to the outputformat for drawing of.attachDevice(hdc); // Drawing directly to the GDI context using (imageObj image = map.draw()) { }; } finally { of.attachDevice(IntPtr.Zero); g.ReleaseHdc(hdc); } } mapImage.Save(args[1]); } catch (Exception ex) { Console.WriteLine( "\nMessage ---\n{0}", ex.Message ); Console.WriteLine( "\nHelpLink ---\n{0}", ex.HelpLink ); Console.WriteLine( "\nSource ---\n{0}", ex.Source ); Console.WriteLine( "\nStackTrace ---\n{0}", ex.StackTrace ); Console.WriteLine( "\nTargetSite ---\n{0}", ex.TargetSite ); } }
/// <summary> /// Create a default layer for creating a preview to another layer /// </summary> /// <param name="originalMap">The original map.</param> /// <param name="originalLayer">The original layer.</param> /// <returns>The created layer object.</returns> private layerObj InitializeDefaultLayer(mapObj originalMap, layerObj originalLayer) { // create a new map object map = new mapObj(null); map.units = MS_UNITS.MS_PIXELS; map.setExtent(0, 0, this.Width, this.Height); map.width = this.Width; map.height = this.Height; outputFormatObj format = originalMap.outputformat; if (map.getOutputFormatByName(format.name) == null) map.appendOutputFormat(format); map.selectOutputFormat(originalMap.imagetype); // copy symbolset for (int i = 1; i < originalMap.symbolset.numsymbols; i++) { symbolObj origsym = originalMap.symbolset.getSymbol(i); map.symbolset.appendSymbol(MapUtils.CloneSymbol(origsym)); } // copy the fontset string key = null; while ((key = originalMap.fontset.fonts.nextKey(key)) != null) map.fontset.fonts.set(key, originalMap.fontset.fonts.get(key, "")); // setting a default font //map.fontset.fonts.set("", // originalMap.fontset.fonts.get(originalMap.fontset.fonts.nextKey(null),"")); // insert a new layer layerObj layer = new layerObj(map); if (originalLayer != null) { // the chart type doesn't support having as single class in it if (originalLayer.type == MS_LAYER_TYPE.MS_LAYER_CHART) layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON; else layer.type = originalLayer.type; originalLayer.open(); // add the sample feature to the layer AddSampleFeature(layer, originalLayer.numitems); if (originalLayer.getResults() == null) originalLayer.close(); // close only is no query results } else { layer.type = MS_LAYER_TYPE.MS_LAYER_ANNOTATION; // add the sample feature to the layer AddSampleFeature(layer, 0); } layer.status = mapscript.MS_ON; return layer; }