non destructive resize of larger image

edited September 2016 in How To...

I used resize to scale a 1000x1000 image to 500x500 But then the original 1000x1000 image is gone. I have to reload it each time, do my thresholding and then scale it down for display each time.

Is there a way to keep the original image after thresholding each time and display the scaled version without having to reload the original each time?

A non destructive resizing to a new smaller image without using brute force loops to create the new scaled image with a new name? if i do a img.resize the original img is gone.

Tagged:

Answers

  • Copy the original image into a tmp image. Resize the tmp image.

  • edited September 2016

    ok tryed that

    PImage tmpimg
    PImage img
    
    tmpimg=loadImage(image.png)
    img=tmpimg
    

    (at this point both height and width =1000) tmpimg.resize(100,100)

    I printed height and width of both at this point and img is now 100x100 as well!

    I didn't resize img

    tmpimg.resize changed both?????

  •      PImage tmpimg;
         PImage img;
    
         tmpimg=loadImage("test.png");
         print("tmpimg width="+tmpimg.width+" height="+tmpimg.height+"\n");
         img=tmpimg;
         print("img width="+img.width+" height="+img.height+"\n");
         tmpimg.resize(480,480);
         print("tmpimg width="+tmpimg.width+" height="+tmpimg.height+"\n");
         print("img width="+img.width+" height="+img.height+"\n");
    

    what gets printed

       tmpimg width=1000 height=1000
       img width=1000 height=1000
       tmpimg width=480 height=480
       img width=480 height=480
    
  • So tmpimg and img are not totally different mem space variables trying to understand how processing works compared to C if i create 2 image variable type PImage are they llike pointers in C? They just point to a space? So is there a syntax for taking a whole image and duplicating it in another space and setting a pointer to point to it?

  • ... if I create 2 image variable type PImage are they like pointers in C?

    Pointers, references, memory addresses mean the same thing! (:|
    Just use PImage's get() method in order to get a clone of it: *-:)
    https://Processing.org/reference/PImage_get_.html

  • edited September 2016

    There's a copy () method on the pimage class.

    Untested but i'd've thought this would work

    tmpImg = img.copy();
    
  • Yes copy() will work

    PImage src = loadImage("blah blah blah.png");
    PImage dest = src.copy();
    dest.resize(500,500);
    dest.save("smaller blah blah blah.png");
    
  • I get error : The method copy(int,int,int,int,int,int,int,int) is the type PImage is not applicable for the arguments() So do i need to provide values for copy or is copy() acceptable in another version? Using 2.2.1

  • edited October 2016 Answer ✓

    copy() has NO arguments it makes a full copy of the image which you can resize leaving the original unaffected.

Sign In or Register to comment.