FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   replicate() problem
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: replicate() problem  (Read 581 times)
sspboyd


replicate() problem
« on: May 15th, 2004, 10:41pm »

Hello all,
I am trying to replicate a few sections of a source image to a new image. I am using the syntax: target.replicate(source, src x,src y,w,h, targ x targ y, w, h);.
 
The problem I am finding is that only the first replicate command works and seemingly only if it is copying from close to 0,0.
 
Here is the code Im using. I'd appreciate some ideas. Is this a bug (or am I due for a forehead slap?).
 
Code:

String imgFileName;
BImage img, tileImg;
void setup(){
  imgFileName = "anyImage.jpg";
  int dimX, dimY;
  img=loadImage(imgFileName);
  dimX=img.width; dimY=img.height;
  tileImg=new BImage(dimX,dimY);
  size(dimX,dimY);
  background(255);
   
  tiles(img, tileImg);
  image(tileImg,0,0);
}
 
void tiles(BImage _img, BImage _tileImg){
  BImage img = _img;
  BImage tileImg=_tileImg;
  int iw,ih; //xs and ys are the spacer vals, iw, ih are img height and width
  iw=30; //replicated img width
  ih=15; //replicated img height
  //works
  tileImg.replicate(img, 0,0,iw,ih,
    0,0,iw,ih);
  // these do not work!
  tileImg.replicate(img, 50,50,iw,ih,
    50,50,iw,ih);
  tileImg.replicate(img, 20,20,iw,ih,
    20,20,iw,ih);
}

 
Thanks a lot,
steve
 

gmail.com w/ sspboyd username
Sprak

20070562007056 WWW
Re: replicate() problem
« Reply #1 on: May 18th, 2004, 9:15pm »

Hm, the basic syntax of the replicate function is incorrect. Perhaps from an older reference? I reworked your tiles() function (using the syntax replicate(srcImg, sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2)), so this should do the trick:
 
Code:

void tiles(BImage _img, BImage _tileImg){  
  BImage img = _img;  
  BImage tileImg=_tileImg;  
  int iw,ih; //xs and ys are the spacer vals, iw, ih are img height and width  
  iw=60; //replicated img width  
  ih=30; //replicated img height  
   
  // the upper left position of the square you want to replicate.
  int sourceXpos = 130;
  int sourceYpos = 60;
   
  // the destination of the replicated area.
  int destXpos = 5;
  int destYpos = 5;
   
  tileImg.replicate(img,  
     sourceXpos,sourceYpos,
     iw+sourceXpos,ih+sourceYpos,  
     destXpos,destYpos,
     iw+destXpos,ih+destYpos );  
}  

 
Hope it helps. Cheers.
 
sspboyd


Re: replicate() problem
« Reply #2 on: May 18th, 2004, 11:50pm »

Quote:
Hope it helps. Cheers.

That totally helps. Thanks for pointing that out. Its always those simple mistakes that screw me up.
 
steve
 
btw: im working on the jmyron stuff again with the info you sent along. thanks
 

gmail.com w/ sspboyd username
Pages: 1 

« Previous topic | Next topic »