node.js - 如何对使用 filestream 和 pngjs 创建的文件进行处理?
问题描述
我需要对 pngjs 和 fs.createWriteStream 创建的图像做一些事情
我尝试使用on finish
,但它不起作用
这是来自 pngjs 页面的一个简单示例:
var fs = require('fs'),
PNG = require('pngjs').PNG;
fs.createReadStream('in.png')
.pipe(new PNG({
filterType: 4
}))
.on('parsed', function() {
for (var y = 0; y < this.height; y++) {
for (var x = 0; x < this.width; x++) {
var idx = (this.width * y + x) << 2;
// invert color
this.data[idx] = 255 - this.data[idx];
this.data[idx+1] = 255 - this.data[idx+1];
this.data[idx+2] = 255 - this.data[idx+2];
// and reduce opacity
this.data[idx+3] = this.data[idx+3] >> 1;
}
}
this.pack().pipe(fs.createWriteStream('out.png').on('finish', function(){
//get image and proccess it to another proccess
// it got error file not found
});
});
它得到错误文件未找到如何解决这个问题?
解决方案
推荐阅读
- lwjgl - 我无法构建 VLCJ。我该如何构建这个?
- ios - 警告是否有害:由于目标没有 Info.plist 文件而跳过代码签名?
- sql - 获取两个日期之间的时间
- python - 将 Pandas 数据框转换为字典用空格重命名列标题
- ios - IBOutlets 在 Storyboard 中连接,等于 nil(空指针错误)
- c# - How to hide or show features/buttons based on user type/login?
- spring-integration - 示例中提供的文件入站适配器示例不起作用
- node.js - 在节点的 child_process 中运行函数
- ruby-on-rails - 如何修复消息“捆绑安装错误 -- 无生产”?
- angular - 两种方式绑定在 userModel 上不起作用