我在 OSX 和 Windows 上都使用 Processing 3(和 2)。离屏 PGraphics 缓冲区中的线性图形比直接绘制的线条要难看得多。看起来形状边缘的抗锯齿效果不佳。
你能帮我把离屏缓冲区图形做得更好吗?
示例图像(右边是丑陋的屏幕外,左边是屏幕上的):
示例代码
PGraphics pg;
void setup(){
size (1024,768, P2D);
pixelDensity(2);
smooth();
pg = createGraphics(width, height, P2D);
noLoop();
}
void draw(){
background (0);
pushMatrix();
translate (width/2-100, height/2);
rotate (PI/6);
stroke(255);
noFill();
strokeWeight(0.5);
rect (0,0,100,100);
popMatrix();
pg.beginDraw();
pg.smooth();
pg.clear();
pg.translate (width/2+100, height/2);
pg.rotate (PI/6);
pg.stroke(255);
pg.noFill();
pg.strokeWeight(0.5);
pg.rect (0,0,100,100);
pg.endDraw();
image(pg,0,0, width, height);
save("shot.png");
}
谢谢!
此问题也已在处理论坛中交叉发布 here .
最佳答案
问题是Processing默认开启抗锯齿引起的。您可以通过调用 smooth()
函数显式启用它,但请注意,这是无关紧要的,因为它已经默认启用。
这会导致您的线条在它们自己的颜色和背景颜色之间变得“模糊”。在屏幕缓冲区中,该背景颜色为黑色。在离屏缓冲区中,该背景颜色是透明的。这就是为什么您的屏幕外方 block 看起来更透明的原因 - 因为它确实如此。
要解决此问题,您需要通过调用 noSmooth()
来禁用抗锯齿功能,或者您需要确保绘制的背景颜色相同。这是 noSmooth()
方法:
PGraphics pg;
void setup(){
size (1024,768, P2D);
noSmooth();
pg = createGraphics(width, height, P2D);
noLoop();
}
void draw(){
background (0);
pushMatrix();
translate (width/2-100, height/2);
rotate (PI/6);
stroke(255);
noFill();
strokeWeight(0.5);
rect (0,0,100,100);
popMatrix();
pg.beginDraw();
pg.noSmooth();
pg.clear();
pg.translate (width/2+100, height/2);
pg.rotate (PI/6);
pg.stroke(255);
pg.noFill();
pg.strokeWeight(0.5);
pg.rect (0,0,100,100);
pg.endDraw();
image(pg,0,0, width, height);
}
关于java - 处理 3 离屏丑陋,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33468589/