2016-04-21 164 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