Skip to content

Home > robinson > rgbaToHex

rgbaToHex() function

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

将rgba颜色字符串转换为十六进制颜色字符串

Signature:

typescript
declare function rgbaToHex(color: string): string;
declare function rgbaToHex(color: string): string;

Parameters

ParameterTypeDescription
colorstringrgba颜色字符串

Returns:

string

{string} 转换后的十六进制颜色字符串,如果输入无效则返回空字符串

Example

javascript
rgbaToHex('rgba(0,0,0,1)'); // '#000000'
rgbaToHex('#000000'); // ''
rgbaToHex('rgba(0,0,0,1)'); // '#000000'
rgbaToHex('#000000'); // ''

Released under the MIT License.