How do I get a rainbow color gradient in C#?

后端 未结 7 2171
太阳男子
太阳男子 2020-12-03 05:18

I\'d like to have an enumeration of Colors based on the rainbow colors (red... yellow... green... blue...).

I see basically two ways to do that:

  1. Cre

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-03 05:44

    In winforms(or anything using GDI+) you could use System.Drawing.Drawing2D.LinearGradientBrush to do the interpolation for you.

    WPF's System.Windows.Media.GradientBrush could work as well. It's abstract so you might end up with WPF's LinearGradientBrush. It's in a different namespace than the other.

    EDIT: since the question was edited to indicate that you want to be tech independent I don't think this answer applies. I'm going to leave it here for now in case someone is looking for Gradients in C#, but if someone finds that objectionable I'll remove the answer.

    I did a quick check to see if you could at least get at some of the functionality in a more independent way (such as getting an array of Point or something). Doesn't appear to be the case.

提交回复
热议问题