Class: ImageUtil
图片相关工具类
Table of contents
Constructors
Methods
- bgGrid
- colorFilter
- createDarkGridImg
- createGridImage
- createLightGridImg
- imageToBase64
- parseImgUrl
- svgToImageUrl
Constructors
constructor
new ImageUtil()
Methods
bgGrid
Static bgGrid(w, h, row, col, fillStyle?, strokeStyle?): string
创建网格背景图片(图片为Base64编码形式: data:image/svg+xml;charset=UTF-8,....)
Parameters
| Name | Type | Default value |
|---|---|---|
w | number | undefined |
h | number | undefined |
row | number | undefined |
col | number | undefined |
fillStyle | string | "#242424" |
strokeStyle | string | "#151515" |
Returns
string
colorFilter
Static colorFilter(image, color): HTMLImageElement
根据图片对象和颜色 生成一个新的Image对象 例如: ImageUtil.colorFilter(image, [255, 0, 0]) 或者自定义滤镜:
const filterImg = ImageUtil.colorFilter(img, function (r, g, b, a) {
g = g > 0 ? 255 : 0;
return [r, g, b, a];
});Parameters
| Name | Type |
|---|---|
image | HTMLImageElement |
color | Function | number[] |
Returns
HTMLImageElement
createDarkGridImg
Static createDarkGridImg(): string
系统默认的‘暗色’背景网格图
Returns
string
createGridImage
Static createGridImage(width?, height?, row?, col?, fillStyle, strokeStyle): string
创建网格背景图片(图片为URL形式: data:image/svg+xml;charset=UTF-8,....)
Parameters
| Name | Type | Default value |
|---|---|---|
width | number | 100 |
height | number | 100 |
row | number | 5 |
col | number | 5 |
fillStyle | string | undefined |
strokeStyle | string | undefined |
Returns
string
createLightGridImg
Static createLightGridImg(): string
系统默认的‘亮色’背景网格图
Returns
string
imageToBase64
Static imageToBase64(image): string
将一个图片对象转成Base64编码格式
Parameters
| Name | Type |
|---|---|
image | HTMLImageElement |
Returns
string
parseImgUrl
Static parseImgUrl(url): any
Parameters
| Name | Type |
|---|---|
url | any |
Returns
any
svgToImageUrl
Static svgToImageUrl(svgString): string
SVG字符串转成图片格式的URL
Parameters
| Name | Type |
|---|---|
svgString | string |
Returns
string
'data:image/svg+xml;charset=UTF-8,' + svgString;