diff --git a/src/item/Item.js b/src/item/Item.js index 75c82d0e..3579f74c 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -1307,9 +1307,13 @@ var Item = Base.extend(Callback, /** @lends Item# */{ matrix.applyToContext(ctx); // See Project#draw() for an explanation of Base.merge() this.draw(ctx, Base.merge({ transforms: [matrix] })); - var raster = new Raster(canvas); - raster.setPosition(topLeft.add(size.divide(2))); ctx.restore(); + var raster = new Raster({ + canvas: canvas, + insert: false + }); + raster.setPosition(topLeft.add(size.divide(2))); + raster.insertAbove(this); // NOTE: We don't need to release the canvas since it now belongs to the // Raster! return raster; diff --git a/src/item/Raster.js b/src/item/Raster.js index 17e0a1e9..b81f300f 100644 --- a/src/item/Raster.js +++ b/src/item/Raster.js @@ -244,7 +244,7 @@ var Raster = Item.extend(/** @lends Raster# */{ this._size = new Size(image.width, image.height); this._canvas = null; this._context = null; - this._changed(/*#=*/ Change.GEOMETRY); + this._changed(/*#=*/ Change.GEOMETRY | /*#=*/ Change.PIXELS); }, /** @@ -330,7 +330,7 @@ var Raster = Item.extend(/** @lends Raster# */{ * * @return {Canvas} the sub image as a Canvas object */ - getSubImage: function(rect) { + getSubCanvas: function(rect) { rect = Rectangle.read(arguments); var ctx = CanvasProvider.getContext(rect.getSize()); ctx.drawImage(this.getCanvas(), rect.x, rect.y, @@ -349,9 +349,13 @@ var Raster = Item.extend(/** @lends Raster# */{ */ getSubRaster: function(rect) { rect = Rectangle.read(arguments); - var raster = new Raster(this.getSubImage(rect)); + var raster = new Raster({ + canvas: this.getSubCanvas(rect), + insert: false + }); raster.translate(rect.getCenter().subtract(this.getSize().divide(2))); raster._matrix.preConcatenate(this._matrix); + raster.insertAbove(this); return raster; }, diff --git a/test/tests/Raster.js b/test/tests/Raster.js index 0331a2c8..551b76f2 100644 --- a/test/tests/Raster.js +++ b/test/tests/Raster.js @@ -91,10 +91,10 @@ asyncTest('Raster#getPixel / setPixel', function(callback) { }; }); -asyncTest('Raster#getSubImage', function(callback) { +asyncTest('Raster#getSubCanvas', function(callback) { var raster = new Raster('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAABlJREFUeNpi+s/AwPCfgYmR4f9/hv8AAQYAHiAFAS8Lwy8AAAAASUVORK5CYII='); raster.onLoad = function() { - var canvas = raster.getSubImage(new Rectangle({ + var canvas = raster.getSubCanvas(new Rectangle({ point: [1, 0], size: [1, 2] }));