Can't display Image: size error even if it is scaled right

Hello! I can’t figure out why I can’t display 1 Image: even if I imported it in the data folder, I wrote the right name with the right extension and scaled to the right size:

import ddf.minim.*;
import ddf.minim.analysis.*;


//Variabili 
int  r = 100;    //Valore di partenza del raggio del cerchio 
float rad = 70;
int stato;
int s = second();
int tempo;

//Immagini
PImage Stanza;  
PImage Foresta;
PImage Uomo1; 
PImage Uomo2; 
PImage Donna;

//Adio player
Minim minim;
AudioPlayer player;
AudioMetaData meta;
BeatDetect beat;

//Lettering e font
PFont f;    //Dichiarazione del font 



void settings(){
  size(1080, 720);
  smooth();
}



void setup(){
  //Sfondo
    background(0);
    Stanza = loadImage("castle-european-interiors-68389.png");
    
  //Centro
    minim = new Minim(this);    //Inizializzazione del player
    player = minim.loadFile("loop midi.Wav");    //Carica file "loop midi.Wav" dalla cartella data dello sketch
    meta = player.getMetaData();
    beat = new BeatDetect();    //Rileva i battiti più rilevanti della canzone
    player.loop(); //La canzone gira in loop 
    //player.play();
    
  //Davanti
    PFont myFont = createFont("Arial-ItalicMT-48", 48);
    textFont(myFont);
    
  //Tempo
    s = 0;
    tempo = second() + 5; 
}


void draw(){ 
  switch (stato){
    case 0 : 
      stato = 0;
      s = 0; 
  
      textSize(50);
      textAlign(CENTER);
      text("PROGETTO PROCESSING", width/2, 360);      //Titolo del progetto
      fill(255);
    
      textSize(30);
      textAlign(CENTER);
      text(".....................................", width/2, 500);   //Campo con informazioni dello studente
      fill(255);

      if ( second() > tempo){
        stato++;
        tempo = second() + 5; 
      }
break;
    
  
    case 1 :
      stato = 1;
      s = 5;
    
        background(Stanza);                        //Here it is the problem
        Stanza.resize(1080, 720);
        beat.detect(player.mix);
        fill(#1A1F18, 20);
        noStroke();
        rect(0, 0, width, height); //Grandezza della finestra della composizione 
        translate(width/2, height/2); //Posiziona la figura al centro della composizione 
        fill(-1, 10);
        ellipse(0, 0, 2*rad, 2*rad);
        stroke(-1, 50);
        int bsize = player.bufferSize();
          for (int i = 0; i < bsize - 1; i+=5){
            float x = (r)*cos(i*2*PI/bsize);
            float y = (r)*sin(i*2*PI/bsize);
            float x2 = (r + player.left.get(i)*100)*cos(i*2*PI/bsize);
            float y2 = (r + player.left.get(i)*100)*sin(i*2*PI/bsize);
            line(x, y, x2, y2);
}
       beginShape();
       noFill();
       stroke(-1, 50);
       endShape();

         if ( second() > tempo){
           stato++;
           tempo = second() + 5; 
         }
break;


    case 2:
      stato = 2; 
      s = 10;
        
        
       
  
  if ( second() > tempo){
    stato++;
    tempo = second() + 5; 
}
break;
  
  
  

}
}

Thank you!

please try to do this in setup() after loading the image (and not in draw())

(besides, the resize command must be before the background, but it’s better in setup())

Chrisir

1 Like

Besides using "Stanza.resize(1080, 720);" in setup(), it won’t work.

void setup(){
  //Sfondo
    Stanza = loadImage("castle-european-interiors-68389.png");
    Stanza.resize(1080, 720);
    background(0);
    
  //Centro
    minim = new Minim(this);    //Inizializzazione del player
    player = minim.loadFile("loop midi.Wav");    //Carica file "loop midi.Wav" dalla cartella data dello sketch
    meta = player.getMetaData();
    beat = new BeatDetect();    //Rileva i battiti più rilevanti della canzone
    player.loop(); //La canzone gira in loop 
    //player.play();
    
  //Davanti
    PFont myFont = createFont("Arial-ItalicMT-48", 48);
    textFont(myFont);
    
  //Tempo
    s = 0;
    tempo = second() + 5; 
}

New error is displayed:
The file castle-european-interiors-68389.png contains bad image data, or may not be an image.
IllegalArgumentException: Width (-1) and height (-1) cannot be <= 0

I previously cut the image to 1080, 720 to fit the sketch, and now i tried to use “Stanza.resize(width, height)” but it doesn’t work at all.

try with another image first

maybe it is a jpg file named falsely png which would confuse processing

2 Likes