Resizing images avoiding blur

edited March 2015 in How To...

Hello guys,

I have an issue with image resizing.

For example, I want that my image, img, change its dimension according with mouseY coordinate.

But doing this, after some iterations image become blurred.

I suppose this happens every resizing is cumulative.

So I set a new image variable, img2, that I reset in every draw() cicle.

PImage img;

void setup() {
  size(400, 400);
  img = loadImage("ball.png");
}

void draw() {
  background(255);
  PImage img2 = img;
  int y = int(map(mouseY, 0, height, 200, 400));
  img2.resize(y, y);
  image(img2, 0, 0);
}

Apparently this don't solve my problem.

Can you guys help me?

Answers

  • edited March 2015 Answer ✓

    Indeed resize() is cumulative since it changes the PImage structure!
    Since you're dynamically redimensioning the PImage's rendering, why don't you call image() w/ 4 parameters? :
    http://processing.org/reference/image_.html

  • Well, this totally help me. Thank you very much.

    PImage img;
    
    void setup() {
      size(400, 400);
      img = loadImage("ball.png");
    }
    
    void draw() {
      background(255);
      int y = int(map(mouseY, 0, height, 200, 400));
      image(img, 0, 0, y, y);
    }
    
Sign In or Register to comment.