-
-
Notifications
You must be signed in to change notification settings - Fork 50
PImage.mask() broken #1065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hey @hkiel Thank you for reporting this, this is a result of us switching to the As for what happened here, turns out that |
I think a great start is to add an error here if the pixelDensities of the images do not match processing4/core/src/processing/core/PImage.java Lines 841 to 844 in c83f44c
Would you have been able to resolve the error if you would have been warned that the pixeldensity between |
I don't really get why pixel densities matter here. I'm working on two images of exactly the same size in pixels. Why would the density matter? |
Hi @hkiel, One thing to know is that The issue comes from the fact that This discrepancy wasn't as apparent when Here's a sketch that demonstrates this: void setup() {
size(100, 100);
pixelDensity(1); // comment this line out (or set to 2) to see the difference
PImage img = createImage(50, 50, RGB);
PGraphics pg = createGraphics(50, 50);
pg.beginDraw();
pg.endDraw();
println("img pixels:", img.pixels.length);
println("pg pixels:", pg.pixels.length);
} Output for
Output for
|
What is the 'correct' way of creating an apropriate mask in my example? I would let |
To create an appropriate mask while avoiding the Here’s a code example: PImage drawImage;
PImage maskImage;
PGraphics drawBuffer;
PGraphics maskBuffer;
void setup() {
size(200, 200);
// Create two PGraphics of the same dimensions
drawBuffer = createGraphics(100, 100);
maskBuffer = createGraphics(100, 100);
}
void draw() {
background(200);
drawBuffer.beginDraw();
drawBuffer.background(255, 0, 0); // Red
drawBuffer.circle(mouseX, mouseY, 20);
drawBuffer.endDraw();
// Get the draw image
drawImage = drawBuffer.get();
// Note: if you don't need to animate the mask
// it will be more efficient to do this in setup() (including the .get call)
maskBuffer.beginDraw();
maskBuffer.background(0);
maskBuffer.fill(255);
maskBuffer.circle(50, 50, map(sin(frameCount*0.01),-1,1,40,80));
maskBuffer.endDraw();
// Get the mask image
maskImage = maskBuffer.get();
drawImage.mask(maskImage);
image(drawImage, 0, 0);
} |
So, finally only the error message of @Stefterv I would not have had a clue how to fix the problem, if I had been warned about different densities, but at least I could have seen that the problem is not the size. |
@SableRaf We should not replace the existing error in |
@Stefterv Even better! What do you think would be a good error message? |
@SableRaf What you wrote seems correct, maybe it can be a bit more specific
and in case of different pixel densities
Dynamically based on the current situation |
I would suggest to not repeat the values. You never know which one is really wrong. |
ok but this is a partial answer. How to have same pixelDensity on mask and picture? return to 1 ? |
Most appropriate sub-area of Processing 4?
Image, Core/Environment/Rendering
Processing version
4.4.3
Operating system
macOS
Steps to reproduce this
Run the following snippet.
Using
mask()
to mask an image leads tomask() can only be used with an image that's the same size.
though both images are created with same size. Worked until 4.4.2.snippet
Additional context
Snippet draws a hexagon with noisy pattern.
Would you like to work on the issue?
assign to someone else, please
The text was updated successfully, but these errors were encountered: