We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › PGraphics scaling
Page Index Toggle Pages: 1
PGraphics scaling? (Read 476 times)
PGraphics scaling?
Mar 25th, 2008, 9:17am
 
I'm trying to scale a PGraphics, and I have no idea how to do it.

I tried calling scale() before image() and also using the image() width and height arguments, but the resulting scaled image has way too much artifact to be remotely usable.

Here is the snippet:

Code:

PGraphics test = createGraphics(300, 300, JAVA2D);

void setup()
{
size(300,300);
noLoop();

background(0);

test.beginDraw();
test.stroke(255);
test.fill(255);
test.point(0, 0);
test.endDraw();
}

void draw()
{

}

void mouseDragged()
{
background(0);
test.beginDraw();
test.stroke(255);
test.fill(255);
test.line(pmouseX, pmouseY, mouseX, mouseY);
test.endDraw();
image(test, 0, 0);
redraw();
}

void keyPressed()
{
background(0);
test.background(0);
image(test, 0, 0, 100, 100);
redraw();
}
Re: PGraphics scaling?
Reply #1 - Mar 26th, 2008, 3:18am
 
Well scaling those lines with such small stroke weights will do that. If you raise the stroke weight to something like 10 or so, you'll have less artifacts. But that might not be what you want.

The other way would probably be to programmatically raise the stroke width. One trivial way would probably be to read each pixel in test and light up each adjacent pixel before resizing.
Re: PGraphics scaling?
Reply #2 - Mar 26th, 2008, 8:48am
 
Well, you're right, increasing the strokeWeight helps. But, I'm curious to know how does Processing resize the image. In photoshop, if I recreate the same kind of graphics and resize it, I only get these artifacts from the nearest neighbors resample. What is processing using? Could I somehow use a different technique like bicubic smoother (which gave me the best result in photoshop) inside of processing?

And on another note, the line() method, from what I understand plots a line between two points. And the beginDraw allows for the PGraphics pixel[] array to be filled up. Then image() copies those pixels unto the display. So what if I wanted to resize my PGraphics so that it's pixel[] array and it's size are actually updated?

Finally, line(), seems like a vector graphics method to me (but I'm no expert at all), a my right to believe that? So I'm wondering, what if I would want to make my PGraphics hold vector graphics instead, from that line(), so that resizing it wouldn't give me any loss of quality which is what vector are good for?
Re: PGraphics scaling?
Reply #3 - Mar 26th, 2008, 10:44am
 
I just started on processing, but i haven't seen a bicubic smoother anywhere yet. You also forget that lines in photoshop are usually aliased, and larger than single pixels.

i don't quite get your second paragraph. But you could also simply move it in 3D space to resize the image. That could be better.

Does processing do vector graphics? i don't think so.

The other method, i didn't really mention because it's quite more involved, is to hold a 2D array of the points where the mouse has dragged to and from, and scale it mathematically yourself. Then use line() to draw it. Or just shift it back in 3D space and draw it.

Page Index Toggle Pages: 1