Shira
YaBB Newbies
Offline
Posts: 2
masking problem
Nov 8th , 2009, 4:00pm
Hi all, I'm trying to divide an image into a number of slices and apply a mask to each one. In setup, I loop through the number of slices and create a PImage for each one using the get() method. I then create a new shape to mask each one (an instance of a class I created) and pass it the width and height of the new PImage. I then apply the shape as a mask to the slice. for some reason I get the following error: "The PImage used with mask() must be the same size as the applet". I printed both their sizes just before I apply the mask and they return the same values. Any ideas? Here's the code: PImage img; PImage shapeImg; PImage slices[]; MaskShape[] mymasks; int numofslices, sliceWidth, sliceHeight; void setup(){ size(300,225); smooth(); img = loadImage("../../../LiverpoolPhotos/liverpool8.jpg"); int numofSlices = int(random(3, 10)); slices = new PImage[numofSlices]; sliceWidth = img.width / numofSlices; sliceHeight = img.height / numofSlices; mymasks = new MaskShape[numofSlices]; for(int i=0; i<numofSlices; i++){ int xpos = int(random(width-50)); int ypos = int(random(height-50)); slices[i] = img.get(i*sliceWidth+1, i*sliceHeight+1, sliceWidth, sliceHeight); mymasks[i] = new MaskShape(sliceWidth, sliceHeight); slices[i].mask(shapeImg); println("slice: "+slices[i].width+", "+slices[i].height); println("shape: "+shapeImg.width+", "+shapeImg.height); image(slices[i], xpos, ypos); } } void draw(){ } class MaskShape{ float randx = 20+random(width-40); float randy = 20+random(height-40); int numofver = int(random(3, 5)); float vercs[][] = new float[numofver][2]; PGraphics pg; int shapeWidth, shapeHeight; MaskShape(int imgWidth, int imgHeight){ shapeWidth = imgWidth; shapeHeight = imgHeight; println(shapeWidth+", "+shapeHeight); pg = createGraphics(shapeWidth, shapeHeight, JAVA2D); vercs[0][0] = randx; vercs[0][1] = randy; vercs[1][0] = randx + random(15, 40); vercs[1][1] = randy + random(-40, 40); vercs[2][0] = randx + random(15, 40); vercs[2][1] = vercs[1][1] + random(15, 40); for (int j=3; j<numofver; j++){ vercs[j][0] = vercs[j-1][0] - random(10, 40); vercs[j][1] = randy+random(15, 40); } pg.background(0); pg.fill(255); pg.beginDraw(); pg.beginShape(); vertex(randx, randy); for (int k=0; k<numofver; k++){ pg.vertex(vercs[k][0], vercs[k][1]); } pg.endShape(CLOSE); pg.endDraw(); shapeImg = pg.get(0, 0, pg.width, pg.height); } } Thanks, Shira