2013-07-25 1 views
2

C#에서 한 색상을 다른 색상으로 부드럽게 변경하는 가장 좋은 방법은 무엇입니까? 내 프로그램은 배터리 수준에 따라 사용자의 색 구성표를 변경합니다.부드러운 색상 변경 방법

내 현재 코드는 private void greater75_Tick(object sender, EventArgs e) {

 if (Environment.OSVersion.Version.Major >= 6 && DwmIsCompositionEnabled()) 
     { 
      PowerStatus ps = SystemInformation.PowerStatus; 
      if (ps.BatteryLifePercent >= 0.75) 
      { 
       ChangeCol.clrAfterGlow = 5; 
       ChangeCol.clrColor = ColorToBgra(Color.Green); 
       ChangeCol.nIntensity += 1; 
       DwmSetColorizationParameters(ref ChangeCol, false); 
      } 
      if (ps.BatteryLifePercent < 0.75) 
      { 
       ChangeCol.clrAfterGlow = 5; 
       ChangeCol.clrColor = ColorToBgra(Color.Blue); 
       ChangeCol.nIntensity += 1; 
       DwmSetColorizationParameters(ref ChangeCol, false); 
      } 
     } 
    } 

이 코드는 사용자의 시스템 색상을 수정하려면이 구조체 및 방법을 사용하고 있습니다.

this guy 감사 및 this other guy

public DWM_COLORIZATION_PARAMS ChangeCol; 
    public struct DWM_COLORIZATION_PARAMS 
    { 
     public uint clrColor; 
     public uint clrAfterGlow; 
     public uint nIntensity; 
     public uint clrAfterGlowBalance; 
     public uint clrBlurBalance; 
     public uint clrGlassReflectionIntensity; 
     public bool fOpaque; 
    } 


    [DllImport("dwmapi.dll", EntryPoint = "#127", PreserveSig = false)] 
    private static extern void DwmGetColorizationParameters(out DWM_COLORIZATION_PARAMS parameters); 

    [DllImport("dwmapi.dll", EntryPoint = "#131", PreserveSig = false)] 
    private static extern void DwmSetColorizationParameters(ref DWM_COLORIZATION_PARAMS parameters, 
                  bool unknown); 

    // Helper method to convert from a Win32 BGRA-format color to a .NET color. 
    private static Color BgraToColor(uint color) 
    { 
     return Color.FromArgb(Int32.Parse(color.ToString("X"), NumberStyles.HexNumber)); 
    } 

    // Helper method to convert from a .NET color to a Win32 BGRA-format color. 
    private static uint ColorToBgra(Color color) 
    { 
     return (uint)(color.B | (color.G << 8) | (color.R << 16) | (color.A << 24)); 
    } 
    [DllImport("dwmapi.dll", PreserveSig = false)] 
    public static extern bool DwmIsCompositionEnabled(); 
    // Gets or sets the current color used for DWM glass, based on the user's color scheme. 

    public static Color ColorizationColor 
    { 
     get 
     { 
      // Call the DwmGetColorizationParameters function to fill in our structure. 
      DWM_COLORIZATION_PARAMS parameters; 
      DwmGetColorizationParameters(out parameters); 

      // Convert the colorization color to a .NET color and return it. 
      return BgraToColor(parameters.clrColor); 
     } 
     set 
     { 
      // Retrieve the current colorization parameters, just like we did above. 
      DWM_COLORIZATION_PARAMS parameters; 
      DwmGetColorizationParameters(out parameters); 

      // Then modify the colorization color. 
      // Note that the other parameters are left untouched, so they will stay the same. 
      // You can also modify these; that is left as an exercise. 
      parameters.clrColor = ColorToBgra(value); 

      // Call the DwmSetColorizationParameters to make the change take effect. 
      DwmSetColorizationParameters(ref parameters, false); 
     } 
    } 

문제 색상 설정,시는 하나 매 0.1 초에 의한 강도 증가는 0, 강도 BLACK 때, 0으로 설정 한 후 점이다, 갑자기 사용자를 혼란스럽게하지 않도록 새로운 색상으로 다소 부드럽게 전환되기를 원합니다.

답변

1

linear 또는 polynomial 보간을 사용할 수 있습니다. 둘 다 원활하게 전환해야합니다. 좀 더 점진적이고 좁아 지도록하려면 logarithmic interpolation을 사용할 수 있습니다.

기술적으로는 초당 10 프레임이기 때문에 매 0.1 초마다 대부분의 사람들에게는 매끄럽지 않을 수 있습니다. 아마 0.05-0.03 초 (20-30 FPS)마다 업데이트를 시도 할 것입니다.

희망이 있습니다.