winforms GMap.NET中的暗模式Map

2cmtqfgy  于 6个月前  发布在  .NET
关注(0)|答案(1)|浏览(47)

我正在使用C#和WinForms开发一个应用程序,带有GMap.NET库。
有人知道如何设置Map的黑暗模式吗?
我目前使用的OpenStreetMap:map.MapProvider = OpenStreetMapProvider.Instance
我看过文档,但我没有找到任何东西。当使用谷歌Map时,可以在CSS中设置颜色参数,但我没有找到直接在C#中定义CSS或主题的方法。

slwdgvem

slwdgvem1#

GMap.NET提供了三种预定义的渲染模式:

  • 默认值,使用Provider定义的颜色
  • 反转模式,将颜色设置为负值=> [GMapControl].NegativeMode
  • 灰度模式,其中所有颜色都转换为灰度;白色为白色=> [GMapControl].GrayScaleMode

这些呈现模式使用ColorMatrix对象来定义每个通道的颜色量。
它还提供了指定自定义ColorMatrix的方法,可设置[GMapControl].ColorMatrix属性。
逆矩阵是这样的~:

var matrixInverted = new ColorMatrix(new float[][] {
    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,  1,  0},
    new float[] {  1,  1,  1,  0,  1}
});

字符串
灰度矩阵如下所示(我的解释):

var matrixGray = new ColorMatrix(new float[][]
{
    new float[] { .2126f, .2126f, .2126f, 0, 0 },
    new float[] { .7152f, .7152f, .7152f, 0, 0 },
    new float[] { .0722f, .0722f, .0722f, 0, 0 },
    new float[] { 0, 0, 0, 1, 0 },
    new float[] { 1, 1, 1, 0, 1 }
});


如果负片模式不完全是您要寻找的,您可以反转灰阶ColorMatrix的颜色:

var matrixGrayInverted = new ColorMatrix(new float[][]
{
    new float[] { -.2126f, -.2126f, -.2126f, 0, 0 },
    new float[] { -.7152f, -.7152f, -.7152f, 0, 0 },
    new float[] { -.0722f, -.0722f, -.0722f, 0, 0 },
    new float[] { 0, 0, 0, 1, 0 },
    new float[] { 1, 1, 1, 0, 1 }
});


然后设定属性:

[GMapControl].ColorMatrix = matrixGrayInverted;


关于这些矩阵的用法,请参阅以下问题中的注解:
How can I gray-out a disabled PictureBox used as Button?
How to use a slider control to adjust the brightness of a Bitmap?
How to apply a fade transition effect to Images using a Timer?
Replacing colour of an Image

相关问题