1 Star 0 Fork 1

telemansoft/node-canvas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
indexed-png-alpha.js 1009 Bytes
一键复制 编辑 原始数据 按行查看 历史
var Canvas = require('..')
var fs = require('fs')
var path = require('path')
var canvas = Canvas.createCanvas(200, 200)
var ctx = canvas.getContext('2d', { pixelFormat: 'A8' })
// Matches the "fillStyle" browser test, made by using alpha fillStyle value
var palette = new Uint8ClampedArray(37 * 4)
var i, j
var k = 0
// First value is opaque white:
palette[k++] = 255
palette[k++] = 255
palette[k++] = 255
palette[k++] = 255
for (i = 0; i < 6; i++) {
for (j = 0; j < 6; j++) {
palette[k++] = Math.floor(255 - 42.5 * i)
palette[k++] = Math.floor(255 - 42.5 * j)
palette[k++] = 0
palette[k++] = 255
}
}
for (i = 0; i < 6; i++) {
for (j = 0; j < 6; j++) {
var index = i * 6 + j + 1.5 // 0.5 to bias rounding
var fraction = index / 255
ctx.fillStyle = 'rgba(0,0,0,' + fraction + ')'
ctx.fillRect(j * 25, i * 25, 25, 25)
}
}
canvas.createPNGStream({ palette: palette })
.pipe(fs.createWriteStream(path.join(__dirname, 'indexed2.png')))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/telemansoft/node-canvas.git
git@gitee.com:telemansoft/node-canvas.git
telemansoft
node-canvas
node-canvas
master

搜索帮助