Hello there,
I am pretty new to processing and what I am going to ask is probably a little stupid but I just can´t get on without help.
I want to write a program to do the following:
- Take a lot of pictures
- “cut out” a stripe of pixels in the middle of every picture (the width of the stripe is the width of the later picture divided by the nomber of images)
- “pace” this stripe to another picture one after another starting at x,y=0 until the right border (wich should coincidate with the total width of all the stripes put together because of how i calculated the width of every stripe)
- show me that resulting picture.
I wrote the following code and get a ArrayOutofBounds error which turns into an Failed to initilize error in the line I put between …:
PImage[] originals;
PImage trans; //the result image
int stripewidth; //with of the stripes to cut out of every image
int transx=0;//x location for translation image
int transy=0;//y loction for translation image
void setup(){
size (1754,1240);
originals = new PImage[121];
trans =createImage(width,height,RGB);
stripewidth=width/originals.length;
for (int i=0;i<originals.length;i++){
originals[i]=loadImage("tfm ("+(i+1)+").png");
}
}
void draw(){
loadPixels();
trans.loadPixels();
for (int i=0;i<originals.length;i++){ //repeat for all the images
originals[i].loadPixels(); //initialize/load
//get access to locations
for (int x=860;x<860+stripewidth;x++){ //"cut out" a stripe of width stripewidth at x=860
for (int y=0;y<height;y++){
int loc =x+y*width;
int transloc =transx+transy*width;
println(transloc);
**trans.pixels[transloc]=originals[i].pixels[loc];** //get pixel from original and put it into trans picture
transy++;
}
transx++;
}
}
updatePixels();
trans.updatePixels();
image(trans,0,0);
}
I guess there are more issues with this code, but I can´t work with it if I dont get any image and I cant get any image until I resolve the error that makes my program break down.
The output I get is this:
Could not run the sketch (Target VM failed to initialize).
But right when it breaks down I can see that it sais ArrayIndexOutOfBoundException: 1539118
Would really appreciate some help, I am sure the problem is very stupid.
Thanks a lot!