Beginner: Cant load image-out of memory

edited November 2015 in Questions about Code

Hey, I just begann using processing, and I have the following problem: I cant load anything! no font, no image, no PShape(image) :(( It would be great, if someone could help me :)

This is basically what I am doing:

First: I Write some code:

//-------------------------------
PImage mapImage;

void setup()
{
  size(600,600);
  mapImage=loadImage("landkarte_dk.svg");
  
}

void draw()
{
 background(200);
 image(mapImage,0,0);
 smooth(); 
}
//---------------------------------------

Then I copy my image into the same folder as the processing file. So the image is right next to the code.

So - i save everything, and hit run. The Emulator/Window opens. The screen stays grey. no image appears. After a few seconds a loading icon appears. After a few minutes I close the "Emulator"(sorry I just cant remember the proper english word).

When I try to load a font this error appears: NullPointer exeption appears. But when I try to load the image(PShape or Pimage) another error appears: Out of memory. (Processing is allowed to use 2gb memory. )

I use processing 3.0.1 and a machine with windows 8.1.

It would be sooo sweet if someone could help me with this.

//my english is realy bad, that is why I tried to write in simple sentences.

Tagged:

Answers

  • edited November 2015

    I wonder whether loadShape() is more appropriate for ".svg" files?
    https://processing.org/reference/loadShape_.html

    Also read about how to post formatted code here:
    https://forum.Processing.org/two/discussion/8045/how-to-format-code-and-text

  • edited November 2015

    actually I wish to use PShape. But I tested font and PImage also, just in case. I also formatted my former post. Thank you.

    This is what I actually tried to do:

    Main:

    Land land;
    PShape s;
    
    void setup()
    {
    Land land=new Land();
    
    size(800,800);
    surface.setResizable(true);
    translate(width/2,height/2,0);
    background(0);
    smooth();
    
    s = loadShape("myImage.svg");
    
    }
    
    void draw()
    {
       land.render(s);
    }
    

    class land render:

    class Land 
    {
      Land()
      {
      }
      
      void render(PShape karte)
      {
        fill(100,0,0,0);
        shape(karte, 0, 0, 50,50);
    }
      
    }
    
  • edited November 2015

    AFAIK, unfortunately Processing can't deal w/ all types of ".svg" files. Dunno the details about it, sorry.

    Anyways, how about your Land class to keep its own PShape; plus coordinates & dimensions?
    You only have to pass the loadShape() once when instantiating it like this: *-:)
    land = new Land(loadShape("myImage.svg"), 0, 0, 50, 50);

    class Land {
      PShape karte;
      int x, y, w, h;
    
      Land(PShape k, int xx, int yy, int ww, int hh) {
        karte = k;
        x = xx;
        y = yy;
        w = ww;
        h = hh;
      }
    
      void render() {
        shape(karte, x, y, w, h);
      }
    }
    
  • Thank you. An out of memory Error wont appear. But the svg File wont show. Maybe I can find out now what the problem is.

  • @Beya said:

    Then I copy my image into the same folder as the processing file. So the image is right next to the code.

    Read the overview, specifically 'Loading and displaying data':

    To add a file to the data folder of a Processing sketch, use the Sketch → Add File menu option, or drag the file into the editor window of the PDE. The data folder will be created if it does not exist already.

Sign In or Register to comment.