我想用渐变色来填充一个矩形,程序片段如下:
        #pragma comment(lib, "msimg32")
        .....        TRIVERTEX        vert[2] ;
        GRADIENT_RECT    gRect;
        vert [0] .x      = rect.left;
        vert [0] .y      = rect.bottom-100;
        vert [0] .Red    = 57;
        vert [0] .Green  = 52;
        vert [0] .Blue   = 173;
        vert [0] .Alpha  = 0;        vert [1] .x      = rect.right;
        vert [1] .y      = rect.bottom; 
        vert [1] .Red    = 0;
        vert [1] .Green  = 48;
        vert [1] .Blue   = 156;
        vert [1] .Alpha  = 0;        gRect.UpperLeft  = 0;
        gRect.LowerRight = 1;
        GradientFill(dc.GetSafeHdc  (),vert,2,&gRect,1,GRADIENT_FILL_RECT_H);
原本打算画蓝色的渐变色(颜色设置没有错),结果成了黑色的,Alpha都设置为255也不行,请问哪里出错了?

解决方案 »

  1.   

    RGB 值写法不对,用16进制
            TRIVERTEX        vert[2] ;
            GRADIENT_RECT    gRect;
            vert [0] .x      = rect.left;
            vert [0] .y      = rect.bottom-100;
            vert [0] .Red    = 0x3900;
            vert [0] .Green  = 0x3400;
            vert [0] .Blue   = 0xad00;
            vert [0] .Alpha  = 0;        vert [1] .x      = rect.right;
            vert [1] .y      = rect.bottom; 
            vert [1] .Red    = 0x0;
            vert [1] .Green  = 0x3000;
            vert [1] .Blue   = 0x9c00;
            vert [1] .Alpha  = 0;        gRect.UpperLeft  = 0;
            gRect.LowerRight = 1;
            GradientFill(pDC->GetSafeHdc(),vert,2,&gRect,1,GRADIENT_FILL_RECT_H);
      

  2.   

    原因在MSDN中有写:The color information of each channel is specified as a value from 0x0000 to 0xff00. This allows higher color resolution for an object that has been split into small triangles for display
      

  3.   

    呵呵,谢谢了,没有仔细看msdn,不好意思,呵呵