HY 我正在编辑本地存储在我的电脑上的各种图像,我对png图像没有任何问题,但是当我尝试编辑jpg图像时,我总是会收到以下错误
this.context.drawImage(this.image, 0, 0, this.imageWidth(), this.image
^
Error: Image given has not completed loading
这是我的代码
Caman('C://images//' + req.body['storedName'], function () {
var regulations = JSON.parse(req.body['regulations']);
this.saturation(regulations.saturation);
this.sepia(regulations.sepia);
this.vibrance(regulations.vibrance);
this.sharpen(regulations.sharpen);
this.brightness(regulations.brightness);
this.contrast(regulations.contrast);
this.exposure(regulations.exposure);
this[req.body['preset']]();
this.render(function () {
this.save('C://images//' + req.body['storedName']);
});
});
知道问题可能是什么?感谢。
修改 在@ lombausch评论后我改变了我的代码,所以现在它看起来像这样,
var myimage = new Canvas.Image();
myimage.onload = function() {
Caman('C://images//' + req.body['storedName'], function () {
var regulations = JSON.parse(req.body['regulations']);
this.saturation(regulations.saturation);
this.sepia(regulations.sepia);
this.vibrance(regulations.vibrance);
this.sharpen(regulations.sharpen);
this.brightness(regulations.brightness);
this.contrast(regulations.contrast);
this.exposure(regulations.exposure);
this[req.body['preset']]();
this.render(function () {
var extension = path.extname(req.body['storedName']);
var filename = path.basename(req.body['storedName'],extension);
this.save('C://images//' + filename + '-caman' + extension);
res.json({ status:'success' });
});
});
};
myimage.onerror = function(err){
console.log(err);
res.json({status:"error", message:err});
};
myimage.src = 'C://images//' + req.body['storedName'];
错误不再显示,但没有任何反应,当我什么都不说,我什么都不说,不是错误消息,也不是其他什么,似乎onload永远不会被解雇。