> For the complete documentation index, see [llms.txt](https://yinglinhan.gitbook.io/framer-x-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yinglinhan.gitbook.io/framer-x-api/library-ku/color/convert.md).

# Convert

Color.**toHex**(color, allow3Char): string

把颜色对象的颜色值的格式转成16进制的格式.，注意这个方法返回的值**不带#号**

```jsx
const blue = Color("#0099FF")

Color.toHex(blue) // "0099FF"
Color.toHex(Color("#FFAAFF"), true) // "FAF"
```

| <p>color: Color</p><p>需要进行颜色转换的颜色</p>                                             |
| --------------------------------------------------------------------------------- |
| <p><strong>allow3Char:</strong> boolean</p><p>如果可以，会返回一个3位的hex格式的颜色值，默认是false</p> |
| **returns:** string                                                               |

Color.**toHexString**(color, allow3Char): string

把颜色对象的颜色值的格式转成16进制的格式，注意这个方法返回的值**带#号**

```jsx
const blue = Color("#0099FF")

Color.toHexString(blue) // "#0099FF"
Color.toHexString(Color("#FFAAFF"), true) // "#FAF"
```

| <p>color: Color</p><p>需要进行颜色转换的颜色</p>                                             |
| --------------------------------------------------------------------------------- |
| <p><strong>allow3Char:</strong> boolean</p><p>如果可以，会返回一个3位的hex格式的颜色值，默认是false</p> |
| **returns:** string                                                               |

Color.**toHsl**(color): ColorHSLA

格式化一个颜色的，返回一个HSL格式的对象

```jsx
const blue = Color("#0099FF")

Color.toHsl(blue) // {h: 204, s: 1, l: 0.5, a: 1}
```

| <p>color: Color</p><p>需要格式化的颜色</p> |
| ---------------------------------- |
| **returns:** ColorHSLA             |

Color.**toHslString**(color): string

格式化一个颜色，把它转变成hsl格式的字符串形式

```jsx
const blue = Color("#0099FF")

Color.toHslString(blue) // "hsl(204, 100%, 50%)"
```

| <p>color: Color</p><p>需要格式化的颜色</p> |
| ---------------------------------- |
| **returns:** string                |

Color.**toHsv**(color): ColorHSVA

格式化一个颜色，把它转变成HSV格式的颜色对象

```jsx
const blue = Color("#0099FF")

Color.toHsv(blue) // {h: 204, s: 1, v: 1, a: 1}"
```

| <p>color: Color</p><p>要进行转换的颜色</p> |
| ---------------------------------- |
| **returns:** ColorHSVA             |

Color.**toHsvString**(color): string

格式化一个颜色实例，把它转换成HSV颜色格式的字符串

| <p>color: Color</p><p>需要格式转换的颜色</p> |
| ----------------------------------- |
| **returns:** string                 |

Color.**toHusl**(color): ColorHSLA

把一个颜色实例转换成HUSL格式的对象

```jsx
const blue = Color("#0099FF")

Color.toHusl(blue) // {h: 250, s: 100, l: 50, a: 1}
```

| <p>color: Color</p><p>需要进行格式转换的颜色</p> |
| ------------------------------------- |
| **returns:** ColorHSLA                |

Color.**toName**(color): string | false

把一个颜色实例的值转换成横css中的颜色名称，如果当前颜色值没有对应可转换的，那就返回false

```jsx
const green = Color("#8FBC8F")

Color.toName(green) // "darkseagreen"
```

| <p>color: Color</p><p>需要被转换的颜色</p> |
| ---------------------------------- |
| **returns:** string \| false       |

Color.**toRgb**(color): ColorRGBA

把颜色实例转换成一个RGB的对象

```jsx
const blue = Color("#0099FF")

Color.toRgb(blue) // {r: 40, g: 175, b: 250, a: 1}
```

| <p>color: Color</p><p>需要转换的颜色实例</p> |
| ----------------------------------- |
| **returns:** ColorRGBA              |

Color.toRgbString(color): string

把颜色实例转换成RGB的格式的字符串形式

```jsx
const blue = Color("#0099FF")

Color.toRgbString(blue) // "rgb(0, 153, 255)"
```

| <p>color: Color</p><p>需要转换的颜色实例</p> |
| ----------------------------------- |
| **returns:** string                 |

Color.**toString**(color): string

把颜色实例转换成RGB的格式的字符串形式

```jsx
const blue = Color("#0099FF")

Color.toString(blue) // "rgb(0, 153, 255)"
```

| <p>color: Color</p><p>需要转换的颜色实例</p> |
| ----------------------------------- |
| **returns:** string                 |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://yinglinhan.gitbook.io/framer-x-api/library-ku/color/convert.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
