本文整理匯總了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);
}
});