c#在对多边行填充选取颜色时可以指定透明度如 Color.FromArgb(200, rgb[0], rgb[1], rgb[2]),在默认的情况下填充会得到透明的效果,但是会遇到一个致命的问题,这种填充方法会使颜色效果叠加,例如,两种浅绿色叠加在一起会变成另一种更绿的颜色(深度)!为解决这个问题可以将 Graghic.CompositingMode = CompositingMode.SourceCopy;//设置填充的时候覆盖的形式
这种情况下两种颜色会覆盖,例如:一个大圆套着一个小圆,先填充大的在填充小的,这样一来颜色就不会叠加啦 该是什么颜色就是什么颜色!!!可是问题又出现啦,透明效果没有啦!!!在sharpmap里每个层用的同一个Graghic对象,因此可以可以考虑将该层另外生成个Graghic对象,然后生成Image,然后对Image设置透明(c#有这种方法代码如下),然后在叠加到地图上!!
float[][] nArray ={ new float[] {1, 0, 0, 0, 0},
new float[] {0, 1, 0, 0, 0},
new float[] {0, 0, 1, 0, 0},
new float[] {0, 0, 0, 0.8f, 0},
new float[] {0, 0, 0, 0, 1}};
ColorMatrix matrix = new ColorMatrix(nArray);
ImageAttributes attributes = new ImageAttributes();
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
Image opacityimage = new Bitmap(image.Width, image.Height);
Graphics ggg = Graphics.FromImage(opacityimage);
ggg.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel,attributes);