diff --git a/src/core/p5.Renderer.js b/src/core/p5.Renderer.js index c869f3e6b4..21ce3bd64b 100644 --- a/src/core/p5.Renderer.js +++ b/src/core/p5.Renderer.js @@ -159,7 +159,7 @@ class Renderer extends p5.Element { } const region = new p5.Image(w*pd, h*pd); - region._pixelDensity = pd; + region.pixelDensity(pd); region.canvas .getContext('2d') .drawImage(canvas, x, y, w * pd, h * pd, 0, 0, w*pd, h*pd); diff --git a/test/unit/image/p5.Image.js b/test/unit/image/p5.Image.js index 2600be63ff..0e44d84a29 100644 --- a/test/unit/image/p5.Image.js +++ b/test/unit/image/p5.Image.js @@ -122,4 +122,23 @@ suite('p5.Image', function() { }); }); }); + + suite('p5.Graphics.get()', function() { + for (const density of [1, 2]) { + test(`width and height match at pixel density ${density}`, function() { + const g = myp5.createGraphics(10, 10); + g.pixelDensity(density); + g.rect(2, 2, 5, 5); + + const img = g.get(); + assert.equal(g.width, img.width); + assert.equal(g.height, img.height); + assert.equal(g.pixelDensity(), img.pixelDensity()); + + g.loadPixels(); + img.loadPixels(); + assert.deepEqual([...g.pixels], [...img.pixels]); + }); + } + }); });