array of images to large
in
Programming Questions
•
8 months ago
hi,
Im loading an array of images, but I want to go trough a large number of images, 110,
the problem is that if my array have more than 12 elements I get a memory error,
I dont want just to increase the memory available, as I know im doing this in a non optimal way,
so how can I refactor my array?, or what to do to show my image gallery?
thanks,
please find the code here:
- PImage [] images = new PImage[10]; //more than 12 images out of memory!!
- int imageCount = 1;
- void setup ()
- {
- size(displayWidth,displayHeight);
- for (int i = 1 ; i<images.length; i++)
- {
- images[i] = loadImage("/images/"+i+".jpg");
- }
- }
- void draw ()
- {
- background (0);
- if (imageCount == 0) {
- imageCount = images.length-1;
- }
- if (imageCount == images.length) {
- imageCount = 1;
- }
- println ("my image count is on::"+imageCount);
- image (images[imageCount], (displayWidth - images[imageCount].width)/2, (displayHeight - images[imageCount].height)/2);
- }
- void keyPressed()
- {
- if (key == CODED) {
- if (keyCode == UP) {
- println("up");
- imageCount++;
- }
- if (keyCode == DOWN) {
- println("DOWN");
- imageCount--;
- }
- if (keyCode == RIGHT) {
- println("RIGHT");
- }
- if (keyCode == LEFT) {
- println("LEFT");
- }
- }
- }
1