C # colors RGB to HSB convert each other

Source: Internet
Author: User

Original: C # color RGB to HSB convert each other

1 /// <summary>2         ///hue, saturation, brightness converted to RGB value3         /// </summary>4         /// <returns></returns>5          Public Static float[] Hsb2rgb (float[] hsb)6         {7             if(hsb[0] == the)8             {9hsb[0] =0;Ten             } One             float[] RGB =New float[3]; A             floatR =0; -             floatg =0; -             floatb =0; the  -             if(hsb[1] ==0) -             { -r = G = b = hsb[2]; +             } -             Else +             { A                 floatSectorpos = hsb[0] /60f; at                 intSectornum = (int) Math.floor (sectorpos); -                 floatFractionalsector = Sectorpos-Sectornum; -                 floatp = hsb[2] * (1-hsb[1]); -                 floatQ = hsb[2] * (1-(hsb[1] *fractionalsector)); -                 floatt = hsb[2] * (1-(hsb[1] * (1-( fractionalsector) )); -                 Switch(Sectornum) in                 { -                      Case 0: tor = hsb[2]; +g =T; -b =p; the                          Break; *                      Case 1: $R =Q;Panax Notoginsengg = hsb[2]; -b =p; the                          Break; +                      Case 2: AR =p; theg = hsb[2]; +b =T; -                          Break; $                      Case 3: $R =p; -g =Q; -b = hsb[2]; the                          Break; -                      Case 4:WuyiR =T; theg =p; -b = hsb[2]; Wu                          Break; -                      Case 5: Aboutr = hsb[2]; $g =p; -b =Q; -                          Break; -                 } A  +             } the             return New float[] {R *255, G *255, b *255 }; -         } $         /// <summary> the         ///convert RGB type colors to HSB the         /// </summary> the         /// <param name= "RGB" ></param> the         /// <returns></returns> -          Public Static float[] RGB2HSB (float[] RGB) in         { the             float[] HSB =New float[3]; the             floatr = rgb[0]; About             floatg = rgb[1]; the             floatb = rgb[2]; the  the             floatMax =Math.max (R, Math.max (g, B)); +             if(Max <=0) -             { the                 returnHSB;Bayi             } the             floatMin =Math.min (R, Math.min (g, B)); the             floatDIF = max-min; -             if(Max >min) -             { the                 if(g = =max) the                 { thehsb[0] = (b-r)/dif * 60f +120f; the                 } -                 Else if(b = =max) the                 { thehsb[0] = (R-G)/dif * 60f +240f; the                 }94                 Else if(B >g) the                 { thehsb[0] = (g-b)/dif * 60f +360f; the                 }98                 Else About                 { -hsb[0] = (g-b)/dif *60f;101                 }102                 if(hsb[0] <0)103                 {104hsb[0] = hsb[0] +360f; the                 }106             }107             Else108             {109hsb[0] =0; the             }111hsb[1] = DIF/Max; thehsb[2] = max/255f;113             returnHSB; the}

C # colors RGB to HSB convert each other

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.