如何使用CamanJS翻转画布

时间:2013-07-29 03:57:57

标签: javascript html5 canvas camanjs

所以我想用CamanJS插件创建一个基于Web的图像编辑器,它被证明是一个爆炸,但我需要创建一个翻转水平功能,事实证明CamanJS没有一个方法,我是想在Caman外面翻转帆布并像这样重新装载

context.translate(imageWidth / 2, imageHeight / 2);
context.scale(-1, 1);
context.drawImage(imageObj, - imageWidth / 2, - imageHeight / 2, imageWidth, imageHeight);
caman.reloadCanvasData();

但没有任何事情发生,任何人都可以提供帮助?

2 个答案:

答案 0 :(得分:2)

这是翻转插件的样子:

Caman.Plugin.register("flip", function () {
    var canvas, ctx;
    var width = this.canvas.width;
    var height = this.canvas.height;

    // Support NodeJS by checking for exports object
    if (typeof exports !== "undefined" && exports !== null) {
        canvas = new Canvas(width, height);
    } else {
        canvas = document.createElement('canvas');
        canvas.width = width;
        canvas.height = height;
    }

    ctx = canvas.getContext('2d');
    ctx.translate(width, 0);
    ctx.scale(-1, 1);
    ctx.drawImage(this.canvas, 0, 0);

    this.replaceCanvas(canvas);
    return this;
});

Caman.Filter.register("flip", function () {
    return this.processPlugin("flip");
});

答案 1 :(得分:0)

如果您正在翻转填充画布的图像,请翻译到画布右侧。

context.translate( canvas.width,0  );
context.scale( -1,1 );
context.drawImage( imageObject,0,0 );