怎样生成彩虹色带

silent_missile 2014-06-14 01:32:39
就是很多程序都有的从红到蓝的色带,用以表示某个变量在某个场中的变化趋势

如果是黑白的那倒是很容易,可是这个从红到蓝我说什么也想不出来,该怎么搞定

各位大大们有没有谁能指点一二
...全文
698 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2014-06-16
  • 打赏
  • 举报
回复
GradientFill [This is preliminary documentation and subject to change.] The GradientFill function fills rectangle and triangle structures. BOOL GradientFill( HDC hdc, CONST PTRIVERTEX pVertex, DWORD dwNumVertex, CONST PVOID pMesh, DWORD dwNumMesh, DWORD dwMode ); Parameters hdc Handle to the destination device context. pVertex Pointer to an array of TRIVERTEX structures that each define a triangle vertex. dwNumVertex Number of vertices. pMesh Array of GRADIENT_TRIANGLE structures in triangle mode, or an array of GRADIENT_RECT structures in rectangle mode. dwNumMesh The number of elements (triangles or rectangles) in pMesh. dwMode Specifies gradient fill mode. This parameter can contain one of the following values. Value Meaning GRADIENT_FILL_RECT_H In this mode, two endpoints describe a rectangle. The rectangle is defined to have a constant color (specified by the TRIVERTEX structure) for the left and right edges. GDI interpolates the color from the top to bottom edge and fills the interior. GRADIENT_FILL_RECT_V In this mode, two endpoints describe a rectangle. The rectangle is defined to have a constant color (specified by the TRIVERTEX structure) for the top and bottom edges. GDI interpolates the color from the top to bottom edge and fills the interior. GRADIENT_FILL_TRIANGLE In this mode, an array of TRIVERTEX structures is passed to GDI along with a list of array indexes that describe separate triangles. GDI performs linear interpolation between triangle vertices and fills the interior. Drawing is done directly in 24- and 32-bit-per-pixel modes. Dithering is performed in 16-, 8.4-, and 1-bit-per-pixel mode. Return Values If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE. Windows NT: To get extended error information, callGetLastError. Remarks To add smooth shading to a triangle, call the GradientFill function with the three triangle endpoints. GDI will linearly interpolate and fill the triangle. To add smooth shading to a rectangle, call GradientFill with the upper-left and lower-right coordinates of the rectangle. There are two shading modes used when drawing a rectangle. In horizontal mode, the rectangle is shaded from left to right. In vertical mode, the rectangle is shaded from top to bottom. The GradientFill function uses a mesh method to specify the endpoints of the object to draw. All vertices are passed to GradientFill in the pVertex array. The pMesh parameter specifies how these vertices are connected to form an object. When filling a rectangle, pMesh points to an array of GRADIENT_RECT structures. Each GRADIENT_RECT structure specifies the index of two vertices in the pVertex array. These two vertices form the upper-left and lower-right boundary of one rectangle. In the case of filling a triangle, pMesh points to an array of GRADIENT_TRIANGLE structures. Each GRADIENT_TRIANGLE structure specifies the index of three vertices in the pVertex array. These three vertices form one triangle. In order to simplify hardware acceleration, this routine is not required to be pixel-perfect in the triangle interior. For more information, see Smooth Shading, Drawing a Shaded Triangle, and Drawing a Shaded Rectangle. QuickInfo Windows NT: Requires version 5.0 or later. Windows: Requires Windows 98 or later. Windows CE: Unsupported. Header: Declared in wingdi.h. Import Library: Included as a resource in msimg32.dll. See Also Bitmaps Overview, Bitmap Functions, EMRGRADIENTFILL, GRADIENT_RECT, GRADIENT_TRIANGLE, TRIVERTEX
www_adintr_com 2014-06-16
  • 打赏
  • 举报
回复
用鼠标从红到蓝划动一下,看看 RGB 三个值的变化规律就行了。
赵4老师 2014-06-16
  • 打赏
  • 举报
回复
提醒: 像素彩色数值的种类 和 屏幕能显示的不同色彩种类 和 人眼能分辨的不同色彩种类 不是一回事!
lm_whales 2014-06-16
  • 打赏
  • 举报
回复
如果不怕麻烦,可以根据IEEEE颜色的定义,波长渐变,或者频率渐变, 然后写出对应的RGB数据
silent_missile 2014-06-15
  • 打赏
  • 举报
回复
引用 3 楼 unituniverse2 的回复:
就是这个东西,我就想知道这个色带是怎么做出来的,关键是里面的计算方法,如果有什么书推荐那就更好了
unituniverse2 2014-06-15
  • 打赏
  • 举报
回复
可以按照此图设计分段函数,一共6段,每段按0~255一共6*256个值
另外远没有用满24bit的,因为除了这个色带中的颜色,其他都是非饱和色(RGB的饱和色就是3个通道中至少有一个是最大值而至少有另一个为最小值。),看上去会很灰暗或者很灰白。
sniffer12345 2014-06-15
  • 打赏
  • 举报
回复
引用 4 楼 silent_missile 的回复:
[quote=引用 3 楼 unituniverse2 的回复:]
就是这个东西,我就想知道这个色带是怎么做出来的,关键是里面的计算方法,如果有什么书推荐那就更好了[/quote] 简单的说吧,不考虑alhpa通道,那么rgb就是一个24bit的值。24bit是一千三百多万?你写个从0到一千三百多万的间隔循环不就行了?
unituniverse2 2014-06-15
  • 打赏
  • 举报
回复
如果你会画图就没什么问题了。用分段函数。计算方法我在2楼已经说了。。。
unituniverse2 2014-06-14
  • 打赏
  • 举报
回复
unituniverse2 2014-06-14
  • 打赏
  • 举报
回复
引用 楼主 silent_missile 的回复:
就是很多程序都有的从红到蓝的色带,用以表示某个变量在某个场中的变化趋势 如果是黑白的那倒是很容易,可是这个从红到蓝我说什么也想不出来,该怎么搞定 各位大大们有没有谁能指点一二
其实就是解析几何。。。想都可以想得到。。。 除了Lab、CMYK比较麻烦(因为需要非线性调整),一般都很容易的吧? RGB色带算是最容易的一种。最开始是红色,然后保持红色不变单纯的线性增加绿色到最大,就完成了从红到橙色到黄色的渐变;接着保持绿色不变而逐渐减小红色到0;再接着。。。 自己想吧。。。
lm_whales 2014-06-14
  • 打赏
  • 举报
回复
可以用 HLS Lab 颜色模式

64,682

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧