HSB矩形调色板绘制方法

HSB矩形调色板绘制方法

绘画应用软件都有一个漂亮的调色板,用于画笔取色,如Photoshop, AutoCad, 3DS,Painter等。矩形的16m色全色谱真彩的调色板比较容易绘制,今介绍几个矩形的HSB调色板样例的绘制方法,很专业,很漂亮。我感觉这漂亮的东西应该分享给大家,对于要编制绘图绘画程序的同行们,以及喜欢色彩的朋友们总会有些帮助。希望大家喜欢。后续我在编写完善的此类圆形和矩形调色板的设计和计算方法。

下面是样例源码,有详细的注释,语法语句都很简单,没什么深奥的理论和公式。

1a748269b7c549c9b74bacf17fa78b61.png

 

colorpad7 (){   //HSB调色板样例(7)
//本例有三种Hue 取色调色板式样
     cs.ClearDraw (0,src);
       cs.SetFillMode (1);//0不填色,1填色
       cs.SetColor (255,220,220,220);
     cs.DrawRect (0,2,720,900);
       cs.SetColor (255,100,100,100);
     cs.DrawRect (15,4,700,800);   //大框线
 
 //绘制调色板( HSV )
          cs.SetStrokeWidth(2);    //线宽          
 //red-yellow-green-cyan-blue-purple-magenta-red
     for (i=0;i<=255;i++){  //调色板:选色条
         cs.SetColor (255,255,i,0); //red-yellow
              cs.DrawLine (i/3+50,80,i/3+50,280);
              cs.DrawLine (i/4+50,350,i/4+50,550);
        cs.SetColor (255,255-i,255,0); //yellow-green
              cs.DrawLine (i/3+135,80,i/3+135,280);
              cs.DrawLine (i/4+114,350,i/4+114,550);
       cs.SetColor (255,0,255,i);  //green-blue
              cs.DrawLine (i/3+220,80,i/3+220,280);
              cs.DrawLine (i/4+178,350,i/4+178,550);
       cs.SetColor (255,0, 255-i,255);  //blue-purple
              cs.DrawLine (i/3+305,80,i/3+305,280);
              cs.DrawLine (i/4+242,350,i/4+242,550);
        cs.SetColor (255,i,0,255); //purple
               cs.DrawLine (i/3+390,80,i/3+390,280);
               cs.DrawLine (i/4+306,350,i/4+306,550);
        cs.SetColor (255,255,0,255-i);  //magenta-red
               cs.DrawLine (i/3+475,80,i/3+475,280);
               cs.DrawLine (i/4+370,350,i/4+370,550);   }

//上(1)调色板高光
          cs.SetFillMode (0) ; 
           cs.SetStrokeWidth(2);    //线宽          
      for (i= 0; i<=120 ; i++ ){  //上调色板高光
            ca=255-i*3 ;
            if (ca<0) ca=0 ;    
            cs.SetColor(ca, 255, 255, 255 );
            cs.DrawRect (51,280, 560,280-i ) ;   }

//下(2)调色板高光和暗部 HSB set brightness
           cs.SetFillMode (0) ; 
           cs.SetStrokeWidth(2);    //线宽          
      for (i= 0; i<=100 ; i++ ){  //高光
            ca=255-i*3 ;
            if (ca<0) ca=0 ;
            cs.SetColor(ca,255,255,255 );
            cs.DrawRect (50,350, 434,350+i ) ;   }

           cs.SetStrokeWidth(1);    //线宽          
      for (i= 0; i<=100 ; i++ ){  //暗部
            ca=255-i*3 ;
            if (ca<0) ca=0 ;
            cs.SetColor(ca, 0, 0, 0 );
            cs.DrawRect (51,550, 434,550-i ) ;   }

//选色条和 ”确定” 按钮
         cs.SetTextStyle (0) ; 
         cs.SetTextSize (24);    
         cs.SetFillMode (1) ; 
         cs.SetColor (255,120,120,120); 
         cs.DrawRect (570,690,664,739);   //按钮
         cs.SetColor (255,250,250,250); 
       cs.DrawRect (571,691,662,737);   //按钮
         cs.SetColor (255,200,200,200); 
       cs.DrawRect (573,693,662,737);   //按钮
         cs.SetColor (255,220,220,220); 
       cs.DrawRect (573,693,658,733);   //按钮
          cs.SetColor (255,0,0,0); 
       cs.DrawText ("确 定 ", 592, 720);
  
             cs.SetStrokeWidth(1); 
             cs.SetFillMode (1) ; 
    for (i=0;i<=255;i++){  // 竖式选色条
          cs.SetColor (255,255,i,0);   //red-y
               cs.DrawLine (610,i/3+80,660,i/3+80);
          cs.SetColor (255,255-i,255,0);   //y-green
               cs.DrawLine (610,i/3+165,660,i/3+165);
          cs.SetColor (255,0,255, i);     //green-cyan
               cs.DrawLine (610,i/3+250,660,i/3+250);
          cs.SetColor (255,0,255-i,255);
               cs.DrawLine (610,i/3+335,660,i/3+335);
          cs.SetColor (255,i,0,255); //purple
               cs.DrawLine (610,i/3+420,660,i/3+420);
          cs.SetColor (255,255,0,255-i);  //magenta-red
               cs.DrawLine (610,i/3+505,660,i/3+505);
              //  cs.Update ();     //显示绘出过程
                        } //竖式选色条

2abd1d1719964b7cab2358ad2abddb22.png

107a924936f045758659249a4caa2460.png 

 

//****  计算HSV ********
 //cs.DrawCircle (dx, 450,7);   //取色
 //mouse 调色板取色 xpos=275 ;  计算 Hue 值
//getpixel ( hdc , xpos, ypos )
//H色板取色,可取得 RGB 值,cr, cg, cb   R,G,B
 //取色点 xpos=306=240°
 //例:调色板宽度x1=50, x2=434, H=(434-50)=384
 //六段画调色板 255/4=64, 64*6=384 = 色板宽度
//此方法:H 板取值,RGB, SB联动变化
 //      1. (255,255,i,0);          //red-yellow
 //      2. (255,255-i,255,0); //yellow-green
 //      3. (255,0, 255, i);         //green-blue
 //      4. (255,0, 255-i,255);  //blue-purple
 //      5. (255, i, 0, 255); //purple
 //      6. (255,255,0,255-i);  //magenta-red
 //依此6段设色,每段60度,可定RGB色
//115,  64=60°,178, 128=120°,242, 192=180°
//306, 256=240°, 434, 384=360°
//H色板 mouse 取色 xpos 值,依此值计算
      dx=365 ;     //mouse xpos > select color 365
      //防越界,图片框内不会越界
       if (dx>434) dx=434 ;  
       if (dx<50) dx=50 ;
       px=1.066 ;    //px=384/360=1.0666 (每度)
          H=(int)((dx-50)/px) ;

//显示 mouse 选色,计算得RGB值
      cs.SetFillMode (1) ;   //画鼠标已选色
    if (H<=60) {             //1. red
          cr=255;       cb=0; 
          cg=(int)(H*255/60) ;     }
    if (H>60&&H<=120) {  //2. yellow
          cg=255;       cb=0; 
          cr=(int)(255-(H-60)*255/60) ;     }
    if (H>120&&H<=180) {   //3. green
          cr=0;       cg=255; 
          cb=(int)((H-120)*255/60) ;     }
    if (H>180&&H<=240) {   //4. cyan
           cg=(int)(255-(H-180)*255/60 ) ;     
           cr=0 ;        cb=255 ;        }      
    if (H>240&&H<=300) {    //5. blue
           cr=(int)((H-240)*255/60 ) ;     
           cg=0 ;   cb=255 ;        }
    if (H>300&&H<=360) {     //6. magenta
           cr=255;  cg=0;  
           cb=(int)(255-(H-300)*255/60 ) ;       }

//依选色值计算,显示2个选取色
          cs.SetColor (255,cr, cg, cb );   //依选色显示
      cs.DrawRect (352,567,432,604);  //H选色show
      cs.DrawRect (570,620,660,660);   //已选色
//H色板画鼠标icon
      cs.SetFillMode (0) ;   //H选色鼠标icon***
      cs.SetStrokeWidth(1); 
            cs.SetColor (255,50,50,50); 
      cs.DrawCircle (dx,450,6);  //xpos=280
          cs.SetColor (255,250,250,250); 
      cs.DrawCircle (dx,450,7);  //xpos=280
 
//取色后,S和V 的初始值是100。即选色条的中心位
        S=100 ;   V=100 ;   //初始值
        //px=195 ;    //H色板取色后游标初始值100
 //此色是选色条getpixel (hdc,xpos,ypos)取色的结果
//选色条颜色依所取色来绘出,六类基色1-6
//依据取色条的游标的xpos值计算 SV值 
//中心点=(x2-x1)/2=295, 
//例   cs.DrawRect (353,620,357,660);   //游标
//例游标 xpos=(357+353)/2=355   px=355;
//依H值的rgb绘制SV选色条:draw S,V bar
            cs.SetStrokeWidth(2); 
            R=cr ;   G=cg ;    B=cb ;
    for (i=0; i<=255; i++){  //调色板:选色条
             R=R+i ; G=G+i ;  B=B+i ;        
             if (R>255) R=255 ;
             if (G>255) G=255 ;
             if (B>255) B=255 ;
         cs.SetColor (255, R, G, B ) ; 
         cs.DrawLine (295+i, 620,295+i ,660);        
             R=R-i ; G=G-i ;  B=B-i ;        
             if (R<0) R=0 ;   
             if (G<0) G=0 ;   
             if (B<0) B=0 ;   
         cs.SetColor (255, R, G, B ) ; 
         cs.DrawLine (295-i ,620,295-i, 660 );       }

//拖动游标改变取色,此例暂未设置游标 xpos 取色
//计算S,V 值,联动SV值显示和已选色更新(新的)
//本例暂未设置,Windows编程,标尺设置很简单
//画标尺,本示例仅示意一下
//用于拖动游标, 中间值=295 , px=40 < 295 < 550
//  (550-40)/100=2.55
//本例下面示例代码可测试px变动,同步改变选色
//变动px值,可测试S,V值的变化和取色变化
          px=460 ;    //游标 xpos 取色中间值295示例
    if (px>=295){
           V=100 ;  
           S=(int)(200-(px-40)/2.55) ;   }
    if (px<295)  {
           S=100 ; 
           V=(int)((px-40)/2.55) ;    }
//画游标
            cs.SetColor (255,220,220,220);
       cs.DrawRect (px-2,620,px+2,660);   //游标
       cs.DrawCircle (px, 618, 2);
       cs.DrawCircle (px, 662, 2);

//标尺拖动,px变动,S,V值变化,同步改变选色
//原H板取色得 cr,cg,cb, 现以SV变动值取得新的颜色

      if (S<100){
          kn=(int)((100-S)*2.55) ;
          r1=cr+kn;  g1=cg+kn;  b1=cb+kn;
          if (r1>255)  r1=255;
          if (g1>255) g1=255;
          if (b1>255) b1=255;
          cs.SetFillMode (1) ; 
          cs.SetColor (255,r1, g1, b1 );   
          cs.DrawRect (570,620,660,660);  }//已选色
     if (V<100){
          kn=(int)((100-V)*2.55) ;
          r1=cr-kn;  g1=cg-kn;  b1=cb-kn;
          if (r1<0)  r1=0;
          if (g1<0) g1=0;
          if (b1<0) b1=0;
          cs.SetFillMode (1) ; 
          cs.SetColor (255,r1, g1, b1 );   
          cs.DrawRect (570,620,660,660);  }//已选色

//画标尺标线
           cs.SetStrokeWidth(1); 
      for (i=0; i<=20; i++){
          dx=i*10*51/20 ;  
          cs.SetColor (255, 250, 250, 250 ) ; 
          cs.DrawLine (dx+39,664,dx+39,670);       }
             cs.SetFillMode (1) ; 
             cs.SetTextSize (16);    
           cs.DrawText ("0 ", 34,685);
           cs.DrawText ("0 ", 544,685);
           cs.DrawText ("< B    100    S > ", 242, 685);
   
//显示RGB,HSB值
           cs.SetFillMode (1) ; 
       cs.SetColor (255,150,150,150);  //标值
       cs.DrawRect (500,325,558,360);   //框线
       cs.DrawRect (500,365,558,400);   //框线
       cs.DrawRect (500,405,558,440);   //框线
       cs.DrawRect (500,475,558,510);   //框线
       cs.DrawRect (500,515,558,550);   //框线
       cs.DrawRect (500,555,558,590);   //框线
          cs.SetFillMode (1) ; 
         cs.SetTextSize (22);    
          cs.SetColor (255,240,240,240);
       cs.DrawText ("R :  ", 469,350);
       cs.DrawText ("G :  ", 469,390);
       cs.DrawText ("B :  ", 469,430);
       ss1=intToString (cr);
       ss2=intToString (cg);
       ss3=intToString (cb);
          tab=0 ;
          if (cr<10) tab=12;
          if (cr>9&&cr<100) tab=6 ;
       cs.DrawText (ss1, 510+tab,350);
          tab=0 ;
          if (cg<10) tab=12;
          if (cg>9&&cg<100) tab=6 ;
      cs.DrawText (ss2, 510+tab,390);
          tab=0 ;
          if (cb<10) tab=12;
          if (cb>9&&cb<100) tab=6 ;
       cs.DrawText (ss3, 510+tab,430);
 
       cs.DrawText ("H :             度", 469,500);
       cs.DrawText ("S :              % ", 469,540);
       cs.DrawText ("B :              % ", 469,580);
       ss1=intToString (H);
       ss2=intToString (S);
       ss3=intToString (V);
          tab=0 ;
          if (H<10) tab=12;
          if (H>9&&H<100) tab=6 ;
       cs.DrawText (ss1, 510+tab,500);
          tab=0 ;
          if (S<10) tab=12;
          if (S>9&&S<100) tab=6 ;
      cs.DrawText (ss2, 510+tab,540);
          tab=0 ;
          if (V<10) tab=12;
          if (V>9&&V<100) tab=6 ;
       cs.DrawText (ss3, 510+tab,580);

//另外RGB选色可加调整小按钮+-选色
//也可使用scollbar来设置,调节RGB色,联动显示
       cs.SetColor (255,250,0,0);  //调色按钮red
       cs.DrawRect (560,325,592,341);   
       cs.DrawRect (560,343,592,360);   
       cs.SetColor (255,0,240,0);  //调色按钮green
       cs.DrawRect (560,365,592,381);   
       cs.DrawRect (560,383,592,400);   
       cs.SetColor (255,0,0,250);  //调色按钮blue
       cs.DrawRect (560,405,592,421);   
       cs.DrawRect (560,423,592,440);   

        cs.SetColor (255,250,250,250);  //调色按钮
        cs.DrawText ("+ ",570,340);
        cs.DrawText ("-- ",570,357);
        cs.DrawText ("+ ",570,380);
        cs.DrawText ("-- ",570,397);
        cs.DrawText ("+ ",570,420);
        cs.DrawText ("-- ",570,437);

//题标,框线
     cs.SetFillMode (0);//0不填色,1填色
           cs.SetColor (255,220,220,220);
           cs.SetStrokeWidth(2);    //线宽          
     cs.DrawRect (50,80,560,280);   //调色板框线
     cs.DrawRect (50,350,434,550);
          cs.SetStrokeWidth(1);    //线宽          
     cs.DrawRect (38,620,550,660);  //选色条框线
     cs.DrawRect (350,565,433,605);  //H选色show
     cs.DrawRect (570,620,660,660);   //已选色
     cs.DrawRect (610,80,660,590);  //竖色条框线
           cs.SetFillMode (1) ; 
           cs.SetColor (255,0,220,0);
           cs.SetTextSize (26);    
      cs.DrawText (" HSB 调色板  示例",80,325);
      cs.DrawText (" HSB 调色板  示例",80,595);
 
 //print 题标
       cs.SetTextSize (40);    
       cs.SetTextStyle (1) ; 
       cs.SetFillMode (1) ; 
    ss=" HSB 调色板 示例( 7 )" ;
       cs.SetColor (255,0,50,0);
    cs.DrawText (ss,44,54);
       cs.SetColor (255,0,250,0);
    cs.DrawText (ss,40,50);
       cs.SetFillMode (0) ; 
    cs.SetColor (255,250,150,0);
    cs.DrawText (ss,40,50);
    cs.Update ();
}//colorpad7 ()

5d53464a584d4557a332d03b18617017.png

 

colorpad8 (){  //HSV 调色板设计示例(8)
//加一个调色板设计样例
//本例以windows窗体图片来示例。其实在Windows中用绘画语句也能画出窗体,我喜欢自己设计绘制各种图形图样,绘制按钮,滚动条等,甚至开个无框窗体,自己在Form上绘制个人风格的自制窗体,加个图片框设置应用功能。
      cs.ClearDraw (0,src);
    fname="/storage/emulated/0/form.jpg";
    cs.DrawBitmap(fname,0,6);   //加底图

          cs.SetFillMode (1);//0不填色,1填色
          cs.SetColor (255,0,0,0);
     cs.DrawRect (0,2,720,22);
     cs.DrawRect (0,2,12,570);
      cs.DrawRect (0,570,720,700);
         cs.SetColor (255,100,100,100);
     cs.DrawRect (28,65,709,521);   //大框线

 //绘制调色板( HSV )
          cs.SetStrokeWidth(1);    //线宽          
 //red-yellow-green-cyan-blue-purple-magenta-red
     for (i=0;i<=255;i++){  //调色板:选色条
        cs.SetColor (255,255,i,0); //red-yellow
              cs.DrawLine (i/3+50,80,i/3+50,280);
        cs.SetColor (255,255-i,255,0); //yellow-green
              cs.DrawLine (i/3+135,80,i/3+135,280);
       cs.SetColor (255,0,255,i);  //green-blue
              cs.DrawLine (i/3+220,80,i/3+220,280);
       cs.SetColor (255,0,255-i,255);  //blue-purple
              cs.DrawLine (i/3+305,80,i/3+305,280);
        cs.SetColor (255,i, 0,255); //purple-magenta
               cs.DrawLine (i/3+390,80,i/3+390,280);
        cs.SetColor (255,255,0,255-i);  //magenta-red
               cs.DrawLine (i/3+475,80,i/3+475,280);      }
 
//画上高光和下暗部 HSB set brightness
           cs.SetFillMode (0) ; 
           cs.SetStrokeWidth(2);    //线宽          
      for (i= 0; i<=100 ; i++ ){  //高光
            ca=255-i*3 ;
            if (ca<0) ca=0 ;
            cs.SetColor(ca,255,255,255 );
            cs.DrawRect (50,80, 560,80+i ) ;   }

           cs.SetStrokeWidth(1);    //线宽          
      for (i= 0; i<=100 ; i++ ){  //暗部
            ca=255-i*3 ;
            if (ca<0) ca=0 ;
            cs.SetColor(ca, 0, 0, 0 );
            cs.DrawRect (51,280, 560,280-i ) ;   }

//选色条显示:当前,新的
         cs.SetTextSize (22);    
         cs.SetFillMode (1) ; 
         cs.SetColor (255,250,0,0); 
      cs.DrawRect (468,305,552,340);   //选色
         cs.SetColor (255,150,0,250); 
       cs.DrawRect (468,365,552,400);   //选色

//****  计算HSV ********
 //调色板尺寸: (50,80,560,280); 
//cs.DrawCircle (270,450,7);   //取色
 //mouse 调色板取色 xpos=270 ;  计算 Hue 值
//getpixel ( hdc , xpos, ypos )
//可取得 RGB 值,cr, cg, cb 
 //取色点 xpos=270 
 //例:调色板宽度x1=50, x2=560, 
// H=(560-50)=510
 //六段画调色板 255/3=85, 85*6=510 = 色板宽度
 //      1. (255,255,i,0);          //red-yellow        0  -  59
 //      2. (255,255-i,255,0);  //yellow-green   60 -119
 //      3. (255,0,255,i);          //green-blue      120-179
 //      4. (255,0,255-i,255);  //blue-purple     180-239
 //      5. (255, i , 0,255);  //purple-magenta  240-299
 //      6. (255,255,0,255-i);  //magenta-red   300-360
//依此6段设色,每段60度,可定RGB色
// 135,  85=60,      220, 170=120°,   305, 255=180° ,  
// 390, 340=240 ,  475, 425=300°,   560, 510=360°
//标xpos=dx,  H=(dx-50)/1.416
      dx=263 ;     //H取色 mousemove(xpos) test
        if (dx>560) dx=560 ;  //防越界,框内不会越界
        if (dx<50)  dx=50 ;

       cs.SetFillMode (0) ;   //画选色鼠标icon
           cs.SetStrokeWidth(1); 
           cs.SetColor (255,250,250,250); 
       cs.DrawCircle (dx,180,5);
           cs.SetColor (255,50,50,50); 
       cs.DrawCircle (dx,180,6);
//依mouse 选色 > 计算H 值
       px=1.416 ;  //px=510/360=1.4166(每度)
          H=(int)((dx-50)/px) ;
   if (H>360) H=H-360 ;  //选色框内取色,值不会超

//H色板显示mouse 选色,计算RGB (r,g,b)
      cs.SetFillMode (1) ;   //画鼠标已选色
    if (H<=60) {               //1. red
          cr=255;       cb=0; 
          cg=(int)(H*255/60) ;     }
    if (H>60&&H<=120) {   //2. yellow
          cg=255;       cb=0; 
          cr=(int)(255-(H-60)*255/60) ;     }
    if (H>120&&H<=180) {   //3. green
          cr=0;       cg=255; 
          cb=(int)((H-120)*255/60) ;     }
    if (H>180&&H<=240) {   //4. cyan
           cg=(int)(255-(H-180)*255/60 ) ;     
           cr=0 ;        cb=255 ;        }      
    if (H>240&&H<=300) {  //5. blue
           cr=(int)((H-240)*255/60 ) ;     
           cg=0 ;   cb=255 ;        }
    if (H>300&&H<=360) {  //6. magenta
           cr=255;  cg=0;  
           cb=(int)(255-(H-300)*255/60 ) ;       }

//依选色值计算,显示取色
      cs.SetColor (255,cr, cg, cb );   //依选色显示
      cs.DrawRect (610,80,665,135);  //已选色show
//选色显示:当前,新的
         cs.SetTextSize (22);    
         cs.SetFillMode (1) ; 
         cs.SetColor (255, cr, cg, cb ); 
      cs.DrawRect (468,305,552,340);   //新的选色
         cs.SetColor (255, cr, cg, cb ); 
       cs.DrawRect (468,365,552,400);   //当前色

//依H绘制选色条:draw SV select color bar
      R=cr ;  G=cg ;   B=cb ;
            cs.SetStrokeWidth(2); 
    for (i=0;i<=255 ;i++){  //调色板:选色条
              R=R+i ;  G=G+i ;  B=B+i ;
          if (R>255) R=255 ;
          if (G>255) G=255 ;
          if (B>255) B=255 ;
      cs.SetColor (255, R, G, B ) ; 
      cs.DrawLine (435-i*1.5, 305,435-i*1.5,340);       
             R=R-i ;  G=G-i ;  B=B-i ;
          if (R<0) R=0 ;
          if (G<0) G=0 ;
          if (B<0) B=0 ;
       cs.SetColor (255, R, G, B ) ; 
       cs.DrawLine (435-i*1.5, 365,435-i*1.5, 400 );  }  

  //画标尺标线,仅展示一下,可不画出
           cs.SetStrokeWidth(1); 
           cs.SetTextStyle (0) ; 
     for (i=0; i<=10; i++){
          dx=i*25.5*1.5 ;  
          cs.SetColor (255, 250, 250, 250 ) ; 
          cs.DrawLine (dx+51,350,dx+51,355);     
          cs.DrawLine (dx+51,407,dx+51,412);       }
             cs.SetFillMode (1) ; 
             cs.SetTextSize (16);    
           cs.DrawText ("0 ", 46,428);
           cs.DrawText ("100 ", 418,428);
               
//取色后,S和B 的初始值是100。即选色条右位
        S=100 ;   V=100 ;   //初始值
//此色是选色条getpixel (hdc,xpos,ypos)取色的结果
//选色条颜色依所取色来绘出,六类基色1-6
//依据取色条的游标的xpos值计算 SV, 
//   cs.DrawRect (50,305, 435,340);  //选色条框线
//   cs.DrawRect (50,365, 435,400);  //选色条框线
// SV 色条 x1=50,x2=435
// S.xpos<435, V=100,   V.xpos<435, S=100
//拖动游标改变取色,此例暂未设置游标 xpos 取色
//计算S,V 值,联动SV值显示和已选色更新(新的)
//本例暂未设置,Windows编程,标尺设置很简单
//可参阅上例(7)拖动游标变动代码
//画游标尺,本示例仅示意一下
//    if (S>=435){  V=100 ;
//          S=(int)(100-(435-xpos)/385*100) ;    }
//    if (V<435){ S=100 ;
//          V=(int)(100-(435-xpos)/385*100) ;    }
//本例暂未设置,Windows编程,标尺设置很简单
      //本示例仅示意:画游标
            cs.SetFillMode (0);//0不填色,1填色
            cs.SetColor (255,250,20,250);
       x1=434 ; x2=434 ;     //S, V值100=434
            cs.SetStrokeWidth(2); 
            cs.SetColor (255,220,220,220);
       cs.DrawRect (x1-2,303,x1+2,343);   //游标尺1
       cs.DrawCircle (x1,303,2);
       cs.DrawCircle (x1,343,2);
       cs.DrawRect (x2-2,363,x2+2,403);   //游标尺2
       cs.DrawCircle (x2,363,2);
       cs.DrawCircle (x2,403,2);

           cs.SetTextStyle (0) ; 
           cs.SetFillMode (1);//0不填色,1填色
           cs.SetColor (255,150,150,150);
       cs.DrawRect (610,147,665,180);   //标值
       cs.DrawRect (610,187,665,220);   
       cs.DrawRect (610,227,665,260);   
       cs.DrawRect (610,287,665,320);   
       cs.DrawRect (610,327,665,360);   
       cs.DrawRect (610,367,665,400);   
          cs.SetTextSize (20);    
          cs.SetColor (255,240,240,240);
       cs.DrawText ("R :  ", 580,170);
       cs.DrawText ("G :  ", 580,210);
       cs.DrawText ("B :  ", 580,250);
      ss1=intToString (cr);
       ss2=intToString (cg);
       ss3=intToString (cb);
          tab=0 ;     //put text center
          if (cr<10) tab=12;
          if (cr>9&&cr<100) tab=6 ;
       cs.DrawText (ss1, 620+tab,170);
          tab=0 ;
          if (cg<10) tab=12;
          if (cg>9&&cg<100) tab=6 ;
      cs.DrawText (ss2, 620+tab,210);
          tab=0 ;
          if (cb<10) tab=12;
          if (cb>9&&cb<100) tab=6 ;
       cs.DrawText (ss3, 620+tab,250);
 
       cs.DrawText ("H :             度", 580,310);
       cs.DrawText ("S :              % ", 580,350);
       cs.DrawText ("B :              % ", 580,390);
       ss1=intToString (H);
       ss2=intToString (S);
       ss3=intToString (V);
          tab=0 ;
          if (H<10) tab=12;
          if (H>9&&H<100) tab=6 ;
       cs.DrawText (ss1, 620+tab,310);
          tab=0 ;
          if (S<10) tab=12;
          if (S>9&&S<100) tab=6 ;
      cs.DrawText (ss2, 620+tab,350);
          tab=0 ;
          if (V<10) tab=12;
          if (V>9&&V<100) tab=6 ;
       cs.DrawText (ss3, 620+tab,390);
       cs.DrawText ("新的 ", 490,360);
       cs.DrawText ("当前 ", 490,420);

//画按钮
          cs.SetColor (255,120,120,120); 
       cs.DrawRect (570,450,664,489);   //按钮
        cs.DrawRect (460,450,554,489);   //按钮
         cs.SetColor (255,250,250,250); 
       cs.DrawRect (572,451,662,486);   //按钮
       cs.DrawRect (462,451,552,486);   //按钮
          cs.SetColor (255,200,200,200); 
       cs.DrawRect (574,454,662,487);   //按钮
       cs.DrawRect (464,454,552,487);   //按钮
          cs.SetColor (255,220,220,220); 
       cs.DrawRect (575,454,658,483);   //按钮
       cs.DrawRect (465,454,548,483);   //按钮
          cs.SetColor (255,0,0,0); 
          cs.SetTextSize (22);    
       cs.DrawText ("确 定 ", 595, 477);
       cs.DrawText ("取 消 ", 485, 477);

//另外RGB选色可加调整小按钮+-选色
//也可使用scrollbar来设置,调节RGB色,
// S 选色条和 B 选色条联动显示选色
       cs.SetColor (255,250,0,0);  //调色按钮red
       cs.DrawRect (667,147,690,163);   
       cs.DrawRect (667,164,690,180);   
       cs.SetColor (255,0,240,0);  //调色按钮green
       cs.DrawRect (667,187,690,203);   
       cs.DrawRect (667,204,690,220);   
       cs.SetColor (255,0,0,250);  //调色按钮blue
       cs.DrawRect (667,227,690,243);   
       cs.DrawRect (667,244,690,260);   

        cs.SetColor (255,250,250,250);  //调色按钮
        cs.DrawText ("+ ",672,162);
        cs.DrawText ("-- ",672,178);
        cs.DrawText ("+ ",672,202);
        cs.DrawText ("-- ",672,218);
        cs.DrawText ("+ ",672,242);
        cs.DrawText ("-- ",672,258);

  
//题标,框线   
          cs.SetFillMode (0);//0不填色,1填色
           cs.SetStrokeWidth(2);    //线宽          
            cs.SetColor (255,190,190,190);
     cs.DrawRect (50,80,560,280);   //调色板框线
          cs.SetStrokeWidth(1);    //线宽          
     cs.DrawRect (610,80,665,135);   //选色rgb框线
     cs.DrawRect (50,305, 435,340);  //选色条框线
     cs.DrawRect (50,365, 435,400);  //选色条框线
     cs.DrawRect (466,305,553,340);   //已选色
 
 //print 题标
     cs.SetTextSize (44);    
       cs.SetTextStyle (1) ; 
       cs.SetFillMode (1) ; 
    ss=" HSB 调色板设计  示例( 8 )" ;
       cs.SetColor (255,0,150,0);
    cs.DrawText (ss,104,624);
       cs.SetColor (255,0,250,0);
    cs.DrawText (ss,100,620);
       cs.SetFillMode (0) ; 
    cs.SetColor (255,250,220,0);
    cs.DrawText (ss,100,620);
    cs.Update ();
}//colorpad8 ()

d4c0211eb6204c00aa420ed31fd0a7b4.png 

//附原制作的矩形调色板源码
colorpad1 (){
    cs.ClearDraw (0,src);
       cs.SetFillMode (1);//0不填色,1填色
       cs.SetTextSize (30);    //*** (1) ****
       cs.SetColor (255,0,0,200);
       cs.DrawText (" 真彩调色板 ",20,35);
         n=(int)(sn);
        ss=intToString (n);
        ss="mode = "+ss ;
        cs.DrawText (ss,520,35);
       cs.SetFillMode (0);//0不填色,1填色
       cs.SetStrokeWidth(2);    //线          
       cs.SetColor (255,0,0,250);
       cs.DrawRect (20,60,670,460);
       cs.Update ();
    //****  16m 全色真彩调色板
//以8为段变色,缩短显示时间。
//此为模拟演示,调色板取色用要逐点绘制
//机器速度快可以逐点绘制
//绘出图寬256*3 ,图高256
//绘出 图片框定标:sx = 3 * 256 , sy = 256
//   canvas.Scale (0, 0)-(768, 255);
//  r1 = 0; g1 = 255; b1 = 255;
//    for (sx=0;sx<256;sx++){     //blue *******
//         r1 = sx;
//       for (sy=0;sy<256;sy++){   
//              g1 = 255 - sy;
//      cs.SetColor (255,r1,g1,b1);
//     cs.DrawRect (sx+50,sy+90,sx+50,sy+90); 
//            cs.Update ();     //显示绘出过程
//             }   }
//      r1= 255; g1= 255; b1= 255;     //green
//      for (sx=256;sx<512;sx++){    // green ********
//           r1=512- sx +255;   b1=512 - sx; 
 //     for (sy=0;sy<256;sy++){     
 //          g1= 255 - sy;   
 //          cs.SetColor (255,r1,g1,b1);
 //     cs.DrawRect (sx+50,sy+90,sx+50,sy+90); 
//             cs.Update ();     //显示绘出过程
//                }  }
//      r1= 0; g1= 255; b1= 0;     //red
//      for (sx=512;sx<769;sx++){    // red ********
//           r1=513- sx +255;   
//      for (sy=0;sy<256;sy++){     
//          g1= 255 - sy;   
//           cs.SetColor (255,r1,g1,b1);
//     cs.DrawRect (sx+50,sy+90,sx+50,sy+90); 
//             cs.Update ();     //显示绘出过程
//                }  }
//此DrawRect (), 其实是DrawPoint (), 然前者的绘制速度较快。

//**** 下面代码以4为段变色,缩短显示时间。
      cs.SetFillMode (1);//0不填色,1填色
        r1= 0; g1= 255; b1= 255;   //blue
      for (i=0;i<64;i++){     // blue ********
             r1=i*4;       sx=i*3;    //太宽,缩一点
     for (j=0;j<64;j++){     
             g1=255-j*4;   sy=j*4;
             cs.SetColor (255,r1,g1,b1);
       cs.DrawRect (sx+50,sy+90,sx+58,sy+98); 
            //  cs.Update ();     //显示绘出过程
                }   }
      r1= 255; g1= 255; b1= 255;    //green
       for (i=64;i<128;i++){    // green ********
            r1=511- i*4 +255;   b1=511- i*4; sx=i*3;
       for (j=0;j<64;j++){     
            g1= 255 - j*4;   sy=j*4 ;
            cs.SetColor (255,r1,g1,b1);
       cs.DrawRect (sx+50,sy+90,sx+58,sy+98); 
              // cs.Update ();     //显示绘出过程
                  }  }
        r1 = 0; g1 = 255; b1 = 0;    //red
      for (i=128;i<192;i++){    // red ********
              r1= i*4-511+255;  sx=i*3 ;
      for (j=0;j<64;j++){
             g1=255 -j*4;   sy=j*4 ;
             cs.SetColor (255,r1,g1,b1);
       cs.DrawRect (sx+50,sy+90,sx+58,sy+98); 
             //  cs.Update ();     //显示绘出过程
                }    }

       cs.SetTextSize (46);    
       cs.SetTextStyle (1) ; 
       cs.SetFillMode (1) ; 
      cs.SetStrokeWidth(1);    //线          
     ss=" 16m色  真彩调色板 示例" ;
    cs.SetColor (255,0,50,0);
    cs.DrawText (ss,84,424);
    cs.SetColor (255,0,250,0);
    cs.DrawText (ss,80,420);
       cs.SetFillMode (0) ; 
    cs.SetColor (255,250,150,0);
    cs.DrawText (ss,80,420);

        cs.Update ();  
}//colorpad1 () 

//**** End ********

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值