本文整理匯總了TypeScript中pngjs.PNG.pack方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript PNG.pack方法的具體用法?TypeScript PNG.pack怎麽用?TypeScript PNG.pack使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pngjs.PNG
的用法示例。
在下文中一共展示了PNG.pack方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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`
)
}
示例3: mkdirp
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);
}
});