|
Author |
Topic: new BImage from non-contiguous pixel selection? (Read 230 times) |
|
sspboyd
|
new BImage from non-contiguous pixel selection?
« on: Apr 21st, 2004, 11:32pm » |
|
Hello, again. New day, new question for the Syntax forum. Is it possible to create a new BImage from a non-contiguous selection of pixels. For example, I'd like to select 4 squares (50x50) from an image and create a new image (100x100) from the selected squares. Pseudo code Code:pix1 = pixels(0,0,10,10); ... pix4 = pixels(50,50,10,10); BImage tile = pix1 at 0,0 + pix2 at 0,50 + pix3 at 50,0 + pix4 at 50,50; |
| I've been looking through the image related functions and nothing is immediately jumping out at me as the answer. Thank you, again! steve
|
gmail.com w/ sspboyd username
|
|
|
TomC
|
Re: new BImage from non-contiguous pixel selection
« Reply #1 on: Apr 22nd, 2004, 12:54am » |
|
BImage.replicate() copies regions from one image to another: http://processing.org/reference/replicate_.html It's not all that clear in the reference (yet, I assume) but to use this on two or more images, use... Code: BImage srcImg = loadImage("a50x50img.jpg"); BImage target = new BImage(100,100); target.replicate(srcImg, 0, 0, 50, 50, // whole of srcImg 50, 50, 100, 100); // bottom-right of target |
|
|
|
|
|
sspboyd
|
Re: new BImage from non-contiguous pixel selection
« Reply #2 on: Apr 22nd, 2004, 5:52am » |
|
Thanks Tom! That works great. I worked out a way of doing it with pixel colour values but your way is much better. Here's how Im using it: Code:BImage bgTile = new BImage(tileW*2, tileH*2); for(int i=0;i<2;i++){ for(int j=0;j<2;j++){ int randImg = int(random(tiles.length)); bgTile.replicate(tiles[randImg], 0,0,tileW,tileH, j*tileW,i*tileH,tileW+(j*tileW), tileH+(i*tileH)); } } |
|
|
gmail.com w/ sspboyd username
|
|
|
|