Skip to content

Commit a5fa292

Browse files
authored
Merge pull request #6542 from davepagurek/fix/img-pixel-density
Fix width/height not matching after get()
2 parents c0acef8 + 897b9e1 commit a5fa292

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/core/p5.Renderer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class Renderer extends p5.Element {
159159
}
160160

161161
const region = new p5.Image(w*pd, h*pd);
162-
region._pixelDensity = pd;
162+
region.pixelDensity(pd);
163163
region.canvas
164164
.getContext('2d')
165165
.drawImage(canvas, x, y, w * pd, h * pd, 0, 0, w*pd, h*pd);

test/unit/image/p5.Image.js

+19
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,23 @@ suite('p5.Image', function() {
122122
});
123123
});
124124
});
125+
126+
suite('p5.Graphics.get()', function() {
127+
for (const density of [1, 2]) {
128+
test(`width and height match at pixel density ${density}`, function() {
129+
const g = myp5.createGraphics(10, 10);
130+
g.pixelDensity(density);
131+
g.rect(2, 2, 5, 5);
132+
133+
const img = g.get();
134+
assert.equal(g.width, img.width);
135+
assert.equal(g.height, img.height);
136+
assert.equal(g.pixelDensity(), img.pixelDensity());
137+
138+
g.loadPixels();
139+
img.loadPixels();
140+
assert.deepEqual([...g.pixels], [...img.pixels]);
141+
});
142+
}
143+
});
125144
});

0 commit comments

Comments
 (0)