2016-04-21 154 views
4

我下载了一套VS2015图标,并通过MSDN guideVS2015图标指南 - 颜色反转

在阅读“使用图像中的颜色”,它指出,“为了使图标显示正确的对比度在Visual Studio的黑暗主题中,反转是以编程方式应用的

我试图在我的应用程序中模仿这种行为,但是当我对图像应用颜色反转时,它不会出现它的方式看起来在VS的黑暗主题:

enter image description here

有谁知道VS如何反转颜色,所以我可以模仿这个?

编辑: 这是我使用的反码 - 这个问题似乎与透明度/阿尔法边缘:

 public static void InvertColors(Bitmap bitmapImage) 
    { 
     var bitmapRead = bitmapImage.LockBits(new Rectangle(0, 0, bitmapImage.Width, bitmapImage.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppPArgb); 
     var bitmapLength = bitmapRead.Stride * bitmapRead.Height; 
     var bitmapBGRA = new byte[bitmapLength]; 
     Marshal.Copy(bitmapRead.Scan0, bitmapBGRA, 0, bitmapLength); 
     bitmapImage.UnlockBits(bitmapRead); 

     for (int i = 0; i < bitmapLength; i += 4) 
     { 
      bitmapBGRA[i] = (byte)(255 - bitmapBGRA[i]); 
      bitmapBGRA[i + 1] = (byte)(255 - bitmapBGRA[i + 1]); 
      bitmapBGRA[i + 2] = (byte)(255 - bitmapBGRA[i + 2]); 
     } 

     var bitmapWrite = bitmapImage.LockBits(new Rectangle(0, 0, bitmapImage.Width, bitmapImage.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppPArgb); 
     Marshal.Copy(bitmapBGRA, 0, bitmapWrite.Scan0, bitmapLength); 
     bitmapImage.UnlockBits(bitmapWrite); 
    } 
+0

你能告诉我们一些代码,显示到目前为止你已经尝试了什么? Visual Studio的源代码是专有的,所以你不可能找到任何能够告诉你它在源代码方面如何工作的人。 –

回答

2

可以使用IVsUIShell5.ThemeDIBits方法适用于就地转化。还有ThemedImageSourceConverter WPF帮助程序类来创建倒置图像。

+0

谢谢 - 我正在进一步调查他们如何生成反转图像,因为我无法使用我的解决方案打包和分发这些库。 – TJF

2

调整色彩,通过它的发光度作为方法IVsUIShell5.ThemeDIBits文档中所述:

图像的亮度被转换使得恒定“卤代”亮度与背景融为一体。这具有消除视觉晕的效果。 “光晕”亮度是不变的常数,不是从输入图像计算出来的。

所以你必须将像素转换成HSL色彩空间,调整颜色并将其转换回来。我迷迷糊糊翻过这个地方:

private double TransformLuminosity(double luminosity) 
    { 
     double haloLuminosity = HaloLuminosity; //Color.FromArgb(255, 246, 246, 246) 
     double themeBackgroundLuminosity = ThemeBackgroundColor.L; 

     if (themeBackgroundLuminosity < LuminosityInversionThreshold) //LuminosityInversionThreshold = 0.5 
     { 
      haloLuminosity = 1.0 - haloLuminosity; 
      luminosity = 1.0 - luminosity; 
     } 

     if (luminosity < haloLuminosity) 
     { 
      return themeBackgroundLuminosity * luminosity/haloLuminosity; 
     } 

     return (1.0 - themeBackgroundLuminosity) * (luminosity - 1.0)/(1.0 - haloLuminosity) + 1.0; 
    } 

我基于灰色的颜色是什么各地的大多数图标Color.FromArgb(255, 246, 246, 246)光环亮度。它没有给出完全相同的结果,但它足够令人满意,并符合我目前的目标。一些例子:

Without transformation

With transformation