An warware: javascript rgb zuwa hex

Babban matsalar amfani da rgb zuwa hex shine cewa yana iya zama da wahala a tuna da wane launi ne. Misali, idan kana son canza kalar akwatin rubutu daga ja zuwa kore, dole ne ka fara canza darajar rgb zuwa hex, sannan ka yi amfani da darajar hex a maimakon darajar ja a lambar.

aiki rgbToHex (r, g, b) {
mayar da "#" + ((1 << 24) + (r << 16) + (g << 8) + b) .toString (16) .slice (1); [/ code] Wannan aiki ne da ke canza ƙimar RGB zuwa ƙimar launi hexadecimal. Ayyukan yana ɗauka a cikin sigogi 3, r, g, da b suna wakiltar ja, kore, da ƙimar launi shuɗi bi da bi. Aikin yana dawo da kirtani wanda ke farawa da "#" sannan kuma darajar launi na hexadecimal. Don samun ƙimar hexadecimal, ƙimar RGB ana fara canzawa zuwa lamba ɗaya ta hanyar canza rago (<<). Bayan haka, ana canza lambar zuwa kirtani a tsarin tushe 16 ta amfani da hanyar toString(). A ƙarshe, ana yanka kirtani daga index 1 gaba don kawar da "0x" a farkon.

Mai canza launi

Babu ginannen mai canza launi a cikin JavaScript, amma akwai ƴan ɗakunan karatu waɗanda zasu iya taimaka muku canza launuka. Ɗayan ɗakin karatu ana kiransa Color.js, kuma yana ba da API mai dacewa don canza launuka tsakanin nau'i daban-daban. Hakanan zaka iya amfani da plugin ɗin mai ɗaukar launi don Chrome ko Firefox don ɗaukar launi cikin sauƙi daga shafin yanar gizon.

Menene RGB

?

RGB yana nufin Red, Green, Blue. RGB samfurin launi ne wanda ke ƙayyadad da yadda ake wakilta launuka akan allon kwamfuta. A cikin RGB, kowane launi ya ƙunshi abubuwa uku: ja, kore, da shuɗi.

Menene HEX

?

Hex shine tsarin lamba wanda ke amfani da lambobi shida don wakiltar lamba. Ana amfani da Hexadecimal a kimiyyar kwamfuta da harsunan shirye-shirye saboda yana da sauƙin aiki da su fiye da binary.

Shafi posts:

Leave a Comment