PC にローカルに保存されているさまざまな画像を編集しています。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 コメントの後にEDITコードを変更したので、次のようになりました。
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'];
エラーはもう表示されませんが、何も起こりません。私が何も言わないときは、エラーメッセージやその他の意味ではなく、オンロードが起動されないようです。