예제 #1
0
    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;
    }
예제 #2
0
    public static void Main(string[] args)
    {
        if (args.Length < 2) usage();
        
        try 
        {
			mapObj map = new mapObj(args[0]);

			using(imageObj image = map.draw())
			{
				// solution 1
				Console.WriteLine ("Drawing map: '" + map.name + "' using imageObj.getBytes");
				
				byte[] img = image.getBytes();
				using (MemoryStream ms = new MemoryStream(img))
				{
					Image mapimage = Image.FromStream(ms);
					mapimage.Save(args[1]);
				}
				
				// solution 2
				Console.WriteLine ("Drawing map: '" + map.name + "' using imageObj.write");

				using (FileStream fs = File.Open("_" + args[1], FileMode.OpenOrCreate, FileAccess.ReadWrite))
				{
					image.write(fs);
				}
			}
        } 
        catch (Exception ex) 
        {
            Console.WriteLine( "GetBytes: ", ex.Message );
        }
    }
예제 #3
0
    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
        {
        WriteableBitmap mapImage = new WriteableBitmap(map.width, map.height, 96, 96, PixelFormats.Bgr32, null);
        Stopwatch stopwatch = new Stopwatch();
        stopwatch.Start();
        using (imageObj image = map.draw())
        {
            // Reserve the back buffer for updates.
            mapImage.Lock();
            try
            {
                if (image.getRawPixels(mapImage.BackBuffer) == (int)MS_RETURN_VALUE.MS_FAILURE)
                {
                    Console.WriteLine("Unable to get image contents");
                }
                // Specify the area of the bitmap that changed.
                mapImage.AddDirtyRect(new Int32Rect(0, 0, map.width, map.height));
            }
            finally
            {
                // Release the back buffer and make it available for display.
                mapImage.Unlock();
            }

            Console.WriteLine("Rendering time: " + stopwatch.ElapsedMilliseconds + "ms");

            // Save the bitmap into a file.
            using (FileStream stream = new FileStream(args[1], FileMode.Create))
            {
                PngBitmapEncoder encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(mapImage));
                encoder.Save(stream);
            }
        }
        }
        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 );	}
    }
예제 #4
0
    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);
        }
    }
예제 #5
0
    public void testimageObj()
    {
        mapObj          map    = new mapObj(mapfile);
        imageObj        image  = map.draw();
        outputFormatObj format = image.format;

        format.setOption("INTERLACE", "OFF");

        map = null;
        gc();
        assert(format.getOption("INTERLACE", "") == "OFF", "testimageObj");
    }
예제 #6
0
    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
        {
            Bitmap    mapImage  = new Bitmap(map.width, map.height, PixelFormat.Format32bppRgb);
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            using (imageObj image = map.draw())
            {
                BitmapData bitmapData = mapImage.LockBits(new Rectangle(0, 0, image.width, image.height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
                try
                {
                    if (image.getRawPixels(bitmapData.Scan0) == (int)MS_RETURN_VALUE.MS_FAILURE)
                    {
                        Console.WriteLine("Unable to get image contents");
                    }
                }
                finally
                {
                    mapImage.UnlockBits(bitmapData);
                }

                Console.WriteLine("Rendering time: " + stopwatch.ElapsedMilliseconds + "ms");

                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);
        }
    }
예제 #7
0
  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 );	}	
  }
예제 #8
0
    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
        {
        Bitmap mapImage = new Bitmap(map.width, map.height, PixelFormat.Format32bppRgb);
        Stopwatch stopwatch = new Stopwatch();
        stopwatch.Start();
        using (imageObj image = map.draw())
        {
            BitmapData bitmapData = mapImage.LockBits(new Rectangle(0, 0, image.width, image.height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
            try
            {
                if (image.getRawPixels(bitmapData.Scan0) == (int)MS_RETURN_VALUE.MS_FAILURE)
                {
                    Console.WriteLine("Unable to get image contents");
                }
            }
            finally
            {
                mapImage.UnlockBits(bitmapData);
            }

            Console.WriteLine("Rendering time: " + stopwatch.ElapsedMilliseconds + "ms");

            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 );	}
    }
예제 #9
0
    public static void Main(string[] args)
    {
        Console.WriteLine("");
        if (args.Length < 2)
        {
            usage();
        }

        mapObj m_obj = new mapObj(args[0]);

        if (args.Length >= 3)
        {
            Console.WriteLine("Setting the imagetype to " + args[2]);
            m_obj.setImageType(args[2]);
        }

        Console.WriteLine("# Map layers " + m_obj.numlayers + "; Map name = " + m_obj.name);
        for (int i = 0; i < m_obj.numlayers; i++)
        {
            Console.WriteLine("Layer [" + i + "] name: " + m_obj.getLayer(i).name);
        }

        imageObj i_obj = m_obj.draw();

        Console.WriteLine("Image URL = " + i_obj.imageurl + "; Image path = " + i_obj.imagepath);
        Console.WriteLine("Image height = " + i_obj.height + "; width = " + i_obj.width);
        try
        {
            i_obj.save(args[1], m_obj);
        }
        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);
        }
    }
예제 #10
0
  public static void Main(string[] args)
  {
    Console.WriteLine("");
	if (args.Length < 2) usage();
    
	mapObj m_obj = new mapObj(args[0]);

	if (args.Length >= 3) 
	{
      Console.WriteLine("Setting the imagetype to " + args[2]);
	  m_obj.setImageType(args[2]);
	}

	Console.WriteLine ("# Map layers " + m_obj.numlayers + "; Map name = " + m_obj.name);	
	for (int i=0; i<m_obj.numlayers; i++) 
	{
	  Console.WriteLine("Layer [" + i + "] name: " + m_obj.getLayer(i).name);
	}
	
    imageObj i_obj = m_obj.draw();
	Console.WriteLine("Image URL = " + i_obj.imageurl + "; Image path = " + i_obj.imagepath);    
	Console.WriteLine("Image height = " + i_obj.height + "; width = " + i_obj.width); 
	try 
	{
	  i_obj.save(args[1],m_obj);
    } 
	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 );	}	
  }
예제 #11
0
    public static void Main(string[] args)
    {
        if (args.Length < 2)
        {
            usage();
        }

        try
        {
            mapObj map = new mapObj(args[0]);

            using (imageObj image = map.draw())
            {
                // solution 1
                Console.WriteLine("Drawing map: '" + map.name + "' using imageObj.getBytes");

                byte[] img = image.getBytes();
                using (MemoryStream ms = new MemoryStream(img))
                {
                    Image mapimage = Image.FromStream(ms);
                    mapimage.Save(args[1]);
                }

                // solution 2
                Console.WriteLine("Drawing map: '" + map.name + "' using imageObj.write");

                using (FileStream fs = File.Open("_" + args[1], FileMode.OpenOrCreate, FileAccess.ReadWrite))
                {
                    image.write(fs);
                }
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("GetBytes: ", ex.Message);
        }
    }
예제 #12
0
	public void testimageObj() 
	{
		mapObj map=new mapObj(mapfile);
		imageObj image = map.draw();
		outputFormatObj format = image.format;
		format.setOption( "INTERLACE", "OFF");

		map=null;
		gc();
		assert(format.getOption("INTERLACE", "") == "OFF", "testimageObj");
	}
예제 #13
0
        private void GenerateTile(double startX, double startY, double initTileGap, int imageSize, int imageBuffer, string savePath, int z, int x, int y, string imageFormat)
        {
            try
            {
                // active map variable
                map.setSize(imageSize + (imageBuffer * 2), imageSize + (imageBuffer * 2));

                // 0/0/0 tile variables
                double startPointX = startX;
                double startPointY = startY;
                double initGap     = initTileGap; // inital distance between tiles, for level 0 is max meters - min meters

                // meta-buffer to fix labeling as a multiplier
                double buffer = 1 + ((double)imageBuffer / (double)imageSize);

                // find the spacing between each tile for level
                double gap = (initGap / Math.Pow(2, z));

                // buffer in meters for each level
                double buffermeters = (gap * buffer) - gap;

                // set map extents for tile x values
                map.extent.minx = (startPointX + (gap * x)) - buffermeters;
                map.extent.maxx = (startPointX + (gap * x) + gap) + buffermeters;

                // set map extents for tile y values
                map.extent.miny = (startPointY + (gap * y)) - buffermeters;
                map.extent.maxy = (startPointY + (gap * y) + gap) + buffermeters;

                // generate map image
                using (imageObj image = map.draw())
                {
                    Image mapImage;

                    byte[] img = image.getBytes();
                    using (MemoryStream ms = new MemoryStream(img))
                    {
                        mapImage = Image.FromStream(ms);
                        ms.Flush();

                        // clip buffer area off generated image
                        if (!(buffer == 0))
                        {
                            Rectangle cropRect = new Rectangle(imageBuffer, imageBuffer, imageSize, imageSize);
                            Bitmap    bmpImage = new Bitmap(mapImage);
                            Bitmap    bmpCrop  = bmpImage.Clone(cropRect, bmpImage.PixelFormat);
                            mapImage = (Image)(bmpCrop);
                        }

                        // save image to disk in TMS format location
                        System.IO.Directory.CreateDirectory(savePath + "\\" + z + "\\" + x);
                        if (imageFormat == "png")
                        {
                            mapImage.Save(savePath + "\\" + z + "\\" + x + "\\" + y + "." + imageFormat, ImageFormat.Png);
                        }
                        if (imageFormat == "jpg")
                        {
                            mapImage.Save(savePath + "\\" + z + "\\" + x + "\\" + y + "." + imageFormat, ImageFormat.Jpeg);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionDump(ex);
            }
        }
예제 #14
0
    public static void Main(string[] args)
    {
        if (args.Length < 2) usage();

          // creating a new map from scratch
          mapObj map = new mapObj(null);
          // adding a layer
          layerObj layer = new layerObj(map);
          layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
          layer.status = mapscript.MS_ON;
          layer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE;
          // define the attribute names from the inline layer
          layer.addProcessing("ITEMS=attribute1,attribute2,attribute3");
          // define the class
          classObj classobj = new classObj(layer);
          classobj.template = "query";   // making the layer queryable
          // setting up the text based on multiple attributes
          classobj.setText("('Shape:' + '[attribute1]' + ' Color:' + '[attribute2]' + ' Size:' + '[attribute3]')");
          // define the label
          classobj.label.outlinecolor = new colorObj(255, 255, 255, 0);
          classobj.label.force = mapscript.MS_TRUE;
          classobj.label.size = (double)MS_BITMAP_FONT_SIZES.MS_MEDIUM;
          classobj.label.position = (int)MS_POSITIONS_ENUM.MS_LC;
          classobj.label.wrap = ' ';
          // set up attribute binding
          classobj.label.setBinding((int)MS_LABEL_BINDING_ENUM.MS_LABEL_BINDING_COLOR, "attribute2");
          // define the style
          styleObj style = new styleObj(classobj);
          style.color = new colorObj(0, 255, 255, 0);
          style.setBinding((int)MS_STYLE_BINDING_ENUM.MS_STYLE_BINDING_COLOR, "attribute2");
          style.setBinding((int)MS_STYLE_BINDING_ENUM.MS_STYLE_BINDING_SIZE, "attribute3");

          Random rand = new Random((int)DateTime.Now.ToFileTime()); ;

          // creating the shapes
          for (int i = 0; i < 10; i++)
          {
          shapeObj shape = new shapeObj((int)MS_SHAPE_TYPE.MS_SHAPE_POINT);

          // setting the shape attributes
          shape.initValues(4);
          shape.setValue(0, Convert.ToString(i));
          shape.setValue(1, new colorObj(rand.Next(255), rand.Next(255), rand.Next(255), 0).toHex());
          shape.setValue(2, Convert.ToString(rand.Next(25) + 5));

          lineObj line = new lineObj();
          line.add(new pointObj(rand.Next(400) + 25, rand.Next(400) + 25, 0, 0));
          shape.add(line);
          layer.addFeature(shape);
          }

          map.width = 500;
          map.height = 500;
          map.setExtent(0,0,450,450);
          map.selectOutputFormat(args[0]);
          imageObj image = map.draw();
          image.save(args[1], map);

          //perform a query
          layer.queryByRect(map, new rectObj(0, 0, 450, 450, 0));

          resultObj res;
          shapeObj feature;
          using (resultCacheObj results = layer.getResults())
          {
          if (results != null && results.numresults > 0)
          {
              // extracting the features found
              layer.open();
              for (int j = 0; j < results.numresults; j++)
              {
                  res = results.getResult(j);
                  feature = layer.getShape(res);
                  if (feature != null)
                  {
                      Console.WriteLine("  Feature: shapeindex=" + res.shapeindex + " tileindex=" + res.tileindex);
                      for (int k = 0; k < layer.numitems; k++)
                      {
                          Console.Write("     " + layer.getItem(k));
                          Console.Write(" = ");
                          Console.Write(feature.getValue(k));
                          Console.WriteLine();
                      }
                  }
              }
              layer.close();
          }
          }
    }
예제 #15
0
    public static void Main(string[] args)
    {
        if (args.Length < 2)
        {
            usage();
        }

        // creating a new map from scratch
        mapObj map = new mapObj(null);
        // adding a layer
        layerObj layer = new layerObj(map);

        layer.type           = MS_LAYER_TYPE.MS_LAYER_POINT;
        layer.status         = mapscript.MS_ON;
        layer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE;
        // define the attribute names from the inline layer
        layer.addProcessing("ITEMS=attribute1,attribute2,attribute3");
        // define the class
        classObj classobj = new classObj(layer);

        classobj.template = "query"; // making the layer queryable
        // setting up the text based on multiple attributes
        classobj.setText("('Shape:' + '[attribute1]' + ' Color:' + '[attribute2]' + ' Size:' + '[attribute3]')");
        // define the label
        classobj.label.outlinecolor = new colorObj(255, 255, 255, 0);
        classobj.label.force        = mapscript.MS_TRUE;
        classobj.label.size         = (double)MS_BITMAP_FONT_SIZES.MS_MEDIUM;
        classobj.label.position     = (int)MS_POSITIONS_ENUM.MS_LC;
        classobj.label.wrap         = ' ';
        // set up attribute binding
        classobj.label.setBinding((int)MS_LABEL_BINDING_ENUM.MS_LABEL_BINDING_COLOR, "attribute2");
        // define the style
        styleObj style = new styleObj(classobj);

        style.color = new colorObj(0, 255, 255, 0);
        style.setBinding((int)MS_STYLE_BINDING_ENUM.MS_STYLE_BINDING_COLOR, "attribute2");
        style.setBinding((int)MS_STYLE_BINDING_ENUM.MS_STYLE_BINDING_SIZE, "attribute3");

        Random rand = new Random((int)DateTime.Now.ToFileTime());;

        // creating the shapes
        for (int i = 0; i < 10; i++)
        {
            shapeObj shape = new shapeObj((int)MS_SHAPE_TYPE.MS_SHAPE_POINT);

            // setting the shape attributes
            shape.initValues(4);
            shape.setValue(0, Convert.ToString(i));
            shape.setValue(1, new colorObj(rand.Next(255), rand.Next(255), rand.Next(255), 0).toHex());
            shape.setValue(2, Convert.ToString(rand.Next(25) + 5));

            lineObj line = new lineObj();
            line.add(new pointObj(rand.Next(400) + 25, rand.Next(400) + 25, 0, 0));
            shape.add(line);
            layer.addFeature(shape);
        }

        map.width  = 500;
        map.height = 500;
        map.setExtent(0, 0, 450, 450);
        map.selectOutputFormat(args[0]);
        imageObj image = map.draw();

        image.save(args[1], map);

        //perform a query
        layer.queryByRect(map, new rectObj(0, 0, 450, 450, 0));

        resultObj res;
        shapeObj  feature;

        using (resultCacheObj results = layer.getResults())
        {
            if (results != null && results.numresults > 0)
            {
                // extracting the features found
                layer.open();
                for (int j = 0; j < results.numresults; j++)
                {
                    res     = results.getResult(j);
                    feature = layer.getShape(res);
                    if (feature != null)
                    {
                        Console.WriteLine("  Feature: shapeindex=" + res.shapeindex + " tileindex=" + res.tileindex);
                        for (int k = 0; k < layer.numitems; k++)
                        {
                            Console.Write("     " + layer.getItem(k));
                            Console.Write(" = ");
                            Console.Write(feature.getValue(k));
                            Console.WriteLine();
                        }
                    }
                }
                layer.close();
            }
        }
    }
예제 #16
0
    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
        {
            WriteableBitmap mapImage  = new WriteableBitmap(map.width, map.height, 96, 96, PixelFormats.Bgr32, null);
            Stopwatch       stopwatch = new Stopwatch();
            stopwatch.Start();
            using (imageObj image = map.draw())
            {
                // Reserve the back buffer for updates.
                mapImage.Lock();
                try
                {
                    if (image.getRawPixels(mapImage.BackBuffer) == (int)MS_RETURN_VALUE.MS_FAILURE)
                    {
                        Console.WriteLine("Unable to get image contents");
                    }
                    // Specify the area of the bitmap that changed.
                    mapImage.AddDirtyRect(new Int32Rect(0, 0, map.width, map.height));
                }
                finally
                {
                    // Release the back buffer and make it available for display.
                    mapImage.Unlock();
                }

                Console.WriteLine("Rendering time: " + stopwatch.ElapsedMilliseconds + "ms");

                // Save the bitmap into a file.
                using (FileStream stream = new FileStream(args[1], FileMode.Create))
                {
                    PngBitmapEncoder encoder = new PngBitmapEncoder();
                    encoder.Frames.Add(BitmapFrame.Create(mapImage));
                    encoder.Save(stream);
                }
            }
        }
        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);
        }
    }