[imageLoad()] disapear when i change size()

Hi, guys!
I’m super new here. I need some help :slight_smile:

I added a image with resolution for example 600x400, and set the size(600,400). Its perfectly works
However,
When i change size to another value for example size(800x600), the image cant be shown.

How do i solve that problem?

Actually, i want to add 2 photo with different resolutions and place them in a different location.
for example first image placed x=0 y=0 [top left corner of image] and second one x=250 y=250 [again top left corner of image].

Thank you all ! :hugs:

Can you post your code? Or better yet, can you post a small example that shows the problem?


void settings(){
 size(1024,551); 
 frog = loadImage("frog.png");
}

void draw(){
 loadPixels();
 frog.loadPixels();
   for(int x=0;x<width;x++){
     for(int y=0;y<height;y++){
       int loc=x+y*width;
       pixels[loc] = frog.pixels[loc];
     }
   }
 updatePixels();
}

When i code like this, the image appears. (My frog.jpg’s resolution is width1024, heigth551)
However if i change the size(1024,551) to another value, it doesnt appear…(with same image.)
Like


void settings(){
 size(1400,700);  // Randomly selected values
 frog = loadImage("frog.png");
}

void draw(){
 loadPixels();
 frog.loadPixels();
   for(int x=0;x<width;x++){
     for(int y=0;y<height;y++){
       int loc=x+y*width;
       pixels[loc] = frog.pixels[loc];
     }
   }
 updatePixels();
}

How can i work with any screen resolution ?

1 Like

-a- first i think that is not related to a

loadImage(file);

problem.

-b- and i think you are aware ( and that should be your first test )
of the default way to show the file / picture

void draw() {
  image(frog,0,0);
}

-c- your way
“loading the image”
AGAIN and AGAIN ( 60 times per sec )
by overwriting the pixels buffer with pixels from picture
( might be for some further experiments )
but be aware that using width and height in the double for loop
is insofar “wrong” ( if not wanted )
as the “lines of picture” logic usually requires to use

frog.width
frog.height

actually i expect that there is a error in case your width*height is bigger as the

frog.width*frog.height = frog.length

( total number of pix in picture )

so please
-a- test the normal image(frog,0,0) way to make sure picture file loads ok.
-b- take the pixels thing out of draw
-c- repair the loop logic

could you please give some more words about
what you want to do?

1 Like

Here is an example of loading two images and displaying them in a simple sketch.

size(600, 600);
PImage img1 = loadImage("https://forum.processing.org/processing-org.jpg");
PImage img2 = loadImage("https://processing.org/img/processing3-logo.png");
image(img1, 0, 0);
image(img2, 250, 250);

…and here again, in a dynamic sketch. The second image is tied to the mouse pointer.

PImage img1;
PImage img2;

void setup() {
  size(600, 600);
  img1 = loadImage("https://processing.org/img/processing3-logo.png");
  img2 = loadImage("https://forum.processing.org/processing-org.jpg");
}

void draw() {
  background(0);
  image(img1, 0, 0);
  image(img2, mouseX, mouseY);
}