PImage / img.resize() unable to scale image up in setup()

edited January 2015 in Using Processing

Hi,

it seems that it's not possible to resize loaded image up in setup(). It works perfectly when I want to make image smaller. And resizing works fine inside draw() when using image(img, x, y, newWidthX, newHeightY) but it's not as good since it has to be resized each frame. Is there a reason why it shouldn't work and is there any workaround so I don't have to scale my image up all the time? It's quite useful for Android apps when I don't know target resolution. For example, I'm trying to make an adventure game test app and I want to resize lo-res background image to width/height of HD device... I'm new to Processing so I'm sorry if it's just some obvious stuff that I missed.

Have a good day, Martin

Tagged:

Answers

  • code please.

    Did you resize before using the size method?

  • edited January 2015

    let's say that jpg or png is 480p

    void setup() {
      size (1280, 720); //or whatever bigger than the original size of the image
    
      layer1 = loadImage("layer1.jpg");
      layer1.resize(width, height);
      //layer1.resize( (int)(width*.5) , 0 ); works fine!
      layer1.loadPixels(); // just for Android...
    
    }
    
    void draw() {
    
      image(layer1, 0, 0);
    
      //etc....
    
    }
    

    EDIT:

    layer1.resize(width, height)// works fine when image size is the same as the size()
    
  • p5 1.5.1 osX as for me your code runs normally...

    PImage layer1;
    
    void setup() {
      size (1280, 720); //or whatever bigger than the original size of the image
    
      layer1 = loadImage("layer1.png");
      layer1.resize(width, height);
      //layer1.resize( (int)(width*.5) , 0 );// works fine!
      layer1.loadPixels(); // just for Android...
      image(layer1, 0, 0);
    
    }
    

    void draw() {

    //image(layer1, 0, 0);// the same if you uncomment, it runs

    //etc....

    }

  • Thanks for your comments, guys.

    Would you mind trying this test file so I know that we're really on the same page and that the problem is just on my side...

    https://www.dropbox.com/s/rcf8x9gu4t5z1fw/resizeUp.zip?dl=1

  • I forgot to mention: I'm using Processing 2.0b7 / Snow Leopard and there's nothing down in console window when I run the sketch...when I tried to add P3D, P2D to the size(), i got this:

    image alt text

  • I tried it in APDE with the same results: resizing down works fine, but it's not possible to scale image over its original size.

  • Answer ✓

    @daremes:: tested: 1.5.1, works, 2.03 works....OSX 10.6.8 SN but the screenshot you posted reminds me that i have got exactly the same with another version (but which one???) for processing when using opengl or p3D...Try with 1.5.1 or 2.03b

  • edited January 2015 Answer ✓

    "2.0b7"
    Uh? Why use an old beta version? Not surprising you have errors...

  • edited January 2015

    Thank you very much, my fault, of course. It works on 2.0.3 (unfortunately, it seems that it's the last version compatible with 10.6.8.) @akenaton @PhilLho

Sign In or Register to comment.