Two improvements

Nov 16, 2009 at 7:57 AM
Edited Nov 16, 2009 at 9:25 AM



Three ideas to improve (if it is even still possible:-))

1/ To be able to change route thickness.

2/ To be able to draw the map in grayscale : this is very useful to make professionnal looking presentation in transport modelling (the field I work in). We usually draw the map in grayscale to be able to see the routes and other colorful objects clearer.

3/ Round the route caps

Three ideas (that works) to do so. I have used them in a quick and dirty way. Maybe you could workout something to fit them in the project.

1/ Add a property public int Thickness; in GMapRoute and an alter the DrawRoutes as so :

protected virtual void DrawRoutes(Graphics g)
         GraphicsState st = g.Save();
         g.SmoothingMode = SmoothingMode.AntiAlias;

         foreach(GMapRoute r in Routes)
            RoutePen.Color = r.Color;
            RoutePen.Width = r.Thickness;

RoutePen.StartCap = LineCap.Round;
            RoutePen.EndCap = LineCap.Round;


2/ in public class WindowsFormsImage : PureImage

use somehow the MakeGrayscale function (the example shone above is quick and dirty : it works; but the image is alaways rendered in grayscale).

ret = new WindowsFormsImage();
m = MakeGrayscale(m as Bitmap);
ret.Img = m;

here the fucntion

public static Bitmap MakeGrayscale(Bitmap original)
          //create a blank bitmap the same size as original
          Bitmap newBitmap = new Bitmap(original.Width, original.Height);

          //get a graphics object from the new image
          Graphics g = Graphics.FromImage(newBitmap);

          //create the grayscale ColorMatrix
          ColorMatrix colorMatrix = new ColorMatrix(
             new float[][]
         new float[] {.3f, .3f, .3f, 0, 0},
         new float[] {.59f, .59f, .59f, 0, 0},
         new float[] {.11f, .11f, .11f, 0, 0},
         new float[] {0, 0, 0, 1, 0},
         new float[] {0, 0, 0, 0, 1}

          //create some image attributes
          ImageAttributes attributes = new ImageAttributes();

          //set the color matrix attribute

          //draw the original image on the new image
          //using the grayscale color matrix
          g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height),
             0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);

          //dispose the Graphics object
          return newBitmap;

Thanks a lot for your wondeful project.


Nov 16, 2009 at 3:36 PM

Hi Radioman, npernoud,

This is similar like I wanted as discussed in this thread. I was thinking about brightness, but gray is also a nice way to put the tiles more to the background.

Maybe you can combine these thoughts.

Now when I want a 60% brightness I do this:


MainMap.GrayScaleMode = true;
                if (GMaps.Instance.ImageProxy != null && GMaps.Instance.ImageProxy is WindowsFormsImageProxy)
                    // 60 is the value
                    float sb = 60 / 255F;

                    float[][] colorMatrixElements = {
                 new float[]{1, 0,  0, 0f, 0f},
                new float[]{0, 1,  0, 0f, 0f},
                new float[]{0,  0,  1, 0f, 0f},
                new float[]{0f, 0f, 0f, 1f, 0f},
                new float[]{sb, sb, sb, 0f, 1f}};

                    System.Drawing.Imaging.ColorMatrix cm = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements);
                    (GMaps.Instance.ImageProxy as WindowsFormsImageProxy).ColorMatrixForGrayScale = cm;

What I suggest is to make ColorMatrixForGrayScale public.

Once again,