本文整理汇总了TypeScript中pngjs.PNG类的典型用法代码示例。如果您正苦于以下问题:TypeScript PNG类的具体用法?TypeScript PNG怎么用?TypeScript PNG使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PNG类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: doneReading
function doneReading() {
if (++filesRead < 2) return;
const diff = new PNG({width: img1.width, height: img1.height});
pixelmatch(img1.data, img2.data, diff.data, img1.width, img1.height, {threshold: 0.1});
diff.pack().pipe(fs.createWriteStream('diff.png'));
}
示例2: Promise
return new Promise(function (resolve, reject) {
const png = new PNG();
png.on('parsed', function () {
resolve(png);
});
png.on('error', function (error) {
reject(error);
});
load(image, png);
});
示例3: export
public static async export(path: string, out: string) {
const buffer = await readFileP(path, { flag: 'r' }).catch(() => {
console.log('File not found or could not be opened')
})
if (!buffer) {
return
}
if (!existsSync(out)) {
await mkdirP(out)
}
const arrayBuffer = toArrayBuffer(buffer)
const wad = await Wad.parse(arrayBuffer)
for (let i = 0; i < wad.entries.length; ++i) {
const entry = wad.entries[i]
if (entry.type !== 'texture') {
continue
}
const msg = `Exporting: ${entry.name}`
process.stdout.write(msg)
const png = new PNG({
width: entry.width,
height: entry.height
})
const mipmap = entry.data
for (let i = 0; i < mipmap.length; ++i) {
png.data[i] = mipmap[i]
}
png.pack().pipe(createWriteStream(`${out}/${entry.name}.png`))
const dots = []
for (let j = 0; j < 30 - msg.length; ++j) {
dots.push('.')
}
process.stdout.write(dots.join('') + 'DONE\n')
}
console.log(
`\nSuccessfully exported all textures from "${resolve(
process.cwd(),
path
)}"\n into "${resolve(process.cwd(), out)}" directory\n`
)
}
示例4: Error
png.bitblt(pngs[1]);
png.bitblt(pngs[1], 1);
png.bitblt(pngs[1], 1, 1);
png.bitblt(pngs[1], 1, 1, 1, 1, 1, 1);
png.on('metadata', metadata => {
metadata.bpp === 1;
});
png.on('parsed', data => {
data.byteLength === 1;
});
png.on('error', error => {
error === new Error('testing');
});
png.on('foo', () => {});
png.pack().adjustGamma();
png.parse('foo').adjustGamma();
png.parse(Buffer.from('foo')).adjustGamma();
png.parse('foo', (error, data) => {
error.stack;
data.adjustGamma();
}).adjustGamma();
PNG.adjustGamma(png);
PNG.bitblt(png, pngs[1]);
PNG.bitblt(png, pngs[1], 1, 1, 1, 1, 1, 1);
示例5: function
mkdirp(dirname(filename), function (err) {
if (err) {
reject(err);
}
else {
var stream = createWriteStream(filename);
stream.on('finish', function () {
resolve();
});
stream.on('error', function (error: Error) {
reject(error);
});
png.pack().pipe(stream);
}
});