1

This is a function of a json object. canvas param is a canvas with image loaded and canvasCtx is a context of the canvas. The problem is that when i move the slider, the canvas is edited only once and if i move it again nothing happens. But if i add the strings that i marked, everything works fine. Why?

EditBrightness : function(canvas, canvasCtx)
{
    var image = new Image(); // image that is used as default image for current operation       

    image.onload = function() {         

        var sliderLayout =  "<div header='Brightness'>" + 
                                "<span></span><br />" +
                                "<div></div>" +
                            "</div>";       

        var dialog = $(sliderLayout).dialog();

        $('div', dialog).slider({
            max : 150,
            min : -150,
            change : function (event, ui) {

                var canvas = $("#edit_canvas")[0];       // <-- Those are
                var canvasCtx = canvas.getContext('2d'); // <-- the strings

                $('span', dialog).html(ui.value);

                canvasCtx.drawImage(image, 0, 0);

                Pixastic.process(canvas, "brightness", {
                    brightness : ui.value
                });
            }
        });
    };

    image.src = canvas.toDataURL();
}
aikixd
  • 506
  • 5
  • 16
  • Nitpick: JSON doesn't do functions - it's a data interchange format. What you're showing is a method in a JavaScript object literal. – Skilldrick Jun 07 '11 at 12:53

1 Answers1

0

Probably because you change canvas, canvasCtx variables which you pass to this method somewhere outside the code which you show us.

bjornd
  • 22,397
  • 4
  • 57
  • 73
  • I've checked the vars with firebug, it seems to be ok. Can it be that pixastic make some permanent changes? – aikixd Jun 07 '11 at 13:01
  • As I see in documentation they use img, not canvas, for manipulations. Also it's stated that img is replaced by canvas. So I think your canvas is replaced by another one, so why it works first time, but not second. It's just destroyed this moment. Try to add image to the DOM next to your canvas and pass the image to the Pixastic method. – bjornd Jun 07 '11 at 13:20