1

我正在编辑本地存储在我的电脑上的各种图像,我对 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 永远不会被解雇。

4

0 回答 0