rgbaUtil.ts 597 B

123456789101112131415161718192021222324
  1. import transparency from './transparency'
  2. //rgba转成16进制
  3. export function hexify(color: string) {
  4. if (color) {
  5. let opacity = '',
  6. rgb = color.split(','),
  7. r = parseInt(rgb[0].split('(')[1]),
  8. g = parseInt(rgb[1]),
  9. b = parseInt(rgb[2].split(')')[0]),
  10. a = Number(rgb[3].split(')')[0] || 1) * 100
  11. transparency.forEach((i, index) => {
  12. if (index == a) {
  13. opacity = i
  14. }
  15. });
  16. return '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1) + opacity
  17. } else {
  18. return
  19. }
  20. }