We are about to switch to a new forum software. Until then we have removed the registration on this forum.
function setup() {
var g = createGraphics(200, 200);
var img = createImage(200, 200, RGB);
g.loadPixels();
println(g.pixels.length);
img.loadPixels();
println(img.pixels.length);
}
print out:
0
160000
Answers
Hmm it should have... Perhaps it is only created after beginDraw()/endDraw() ?
PGraphics
extendsPImage.Therefore PGraphics got everything a PImage does.
https://Processing.org/reference/extends.html
Oooopps, my bad also. I missed the
varand the tag. The code you posted just works fine in java mode...Can we make a request for this feature in P5?
@GotoLoop https://github.com/processing/p5.js/issues/995 I guess you were heard. <:-P I was trying to fix it.
I was just wondering about that... I was hoping this would work:
But I don't think it does. (PS how do I do a fancy code block?)
I was trying to code an example to test p5.Image & p5.Graphics together and stumbled in a puzzling nasty halting bug after issuing updatePixels(), which I've got no idea why! ~X(
<script src=http://p5js.org/js/p5.min.js defer></script> <script> /** * Image & Graphics Test (v1.2) * GoToLoop (2016-Feb-20) * * https://forum.Processing.org/two/discussion/13857/ * does-offscreen-graphics-buffer-has-a-pixels-array */ function setup() { createCanvas(600, 400) noLoop() } function draw() { "use strict" background(0) const im = createImage(width, height>>1), pg = createGraphics(width, height>>1), red = [0xff, 0, 0, 0xff], blue = [0, 0, 0xff, 0xff] makeImage(im, red) // p5.Image halts whole sketch! //makeImage(pg, blue) // p5.Graphics doesn't halt, but doesn't work either! //loadPixels() //set(0, 0, im) //set(0, height>>1, pg) //updatePixels() image(im, 0, 0) image(pg, 0, height>>1) } function makeImage(img, c) { "use strict" img.loadPixels() const p = img.pixels for (let i = 0; i < p.length; i += 4) for (let j = 0; j < 4; p[i+j] = c[j++]); img.updatePixels() // halt bug?! return img } </script>Found the halting bug. 2nd
forloop needed an ending semi-colon;in order not to pick up
img.updatePixels()! X_XBut it turns out that p5.Renderer objects don't have property pixels[] at all!
But surprisingly, main p5.Renderer canvas is the exception and it got 1!!! 8-}