fredciel
YaBB Newbies
Offline
Posts: 7
Re: memory problem
Reply #5 - Nov 20th , 2008, 2:22pm
I don't think I create a lot of objets in the memory because I just use one image (500x500 pixel) as a stamp... I already use createGraphics() and I render it offscreen without displaying it... this is the code I'm using actually.... String gStampImageName="p2"; String gArtworkName= "BigImage"; // this image will be saved in png int gBigImageSize = 4000; // here I would like to have 12000 float gStampSize=80; // same scale as the displaysize Stamp gDrawingStamp; PImage gSourceimage; int gDisplaySize=1000;// size of the preview int gBackgroundColor=0; float gStampRapportSize; PGraphics gBigImage = createGraphics(gBigImageSize, gBigImageSize, JAVA2D); Boolean gFiniFlag=false; int gCounter=0; int gUpdateFrameCounter=0; int gUpdateFrameNbr=100; // we have a preview every 100 stamps float gStartTime; void setup() { size(gDisplaySize,gDisplaySize); background(gBackgroundColor); smooth(); gStampRapportSize=gBigImageSize/gDisplaySize; gDrawingStamp=new Stamp(gStampImageName,113,606,0,0); // 4 values x1,y1,x2,y2 for the regpoint and the orientation gStartTime= millis(); gBigImage.beginDraw(); gBigImage.background(gBackgroundColor); gBigImage.smooth(); } void draw() { while (gUpdateFrameCounter<gUpdateFrameNbr) { gCounter++; gUpdateFrameCounter++; float r= gCounter*.5; float angle= gCounter*.5; gDrawingStamp.Show(gDisplaySize/2+r*cos(angle) ,gDisplaySize/2.0+r*sin(angle),angle,random(255), random(255), random(255), gStampSize); } gBigImage.endDraw(); image(gBigImage, 0, 0,gDisplaySize,gDisplaySize); gBigImage.beginDraw(); if (gCounter>=1000) { gFiniFlag=true; } else{ gUpdateFrameCounter=0; } if (gFiniFlag) { gBigImage.endDraw(); float t=millis() - gStartTime; println(" Computing Time = " + t ); gStartTime=millis(); gBigImage.save( gArtworkName +".png"); t=millis() - gStartTime; println(" Save Time = " + t ); noLoop(); } } class Stamp { String myStampName; int myStartX; int myStartY; int myEndX; int myEndY; float myDirection; PImage myStampImage; float myStampRealSize; Stamp(String Name, int sx,int sy,int ex,int ey) { myStampName=Name; myStartX = sx; myStartY = sy; myEndX=ex; myEndY=ey; myDirection = atan2(ey-sy, ex-sx); myStampRealSize=Distance( sx, sy, ex,ey); myStampImage = loadImage( myStampName + ".png"); } void Show( float theX,float theY,float theAngle,float theRed,float theGreen,float theBlue,float theStampSize) { float MySize= gStampRapportSize*theStampSize/myStampRealSize; gBigImage.translate(theX*gStampRapportSize,theY*gStampRapportSize); gBigImage.rotate(theAngle+ myDirection); gBigImage.tint(theRed,theGreen,theBlue); gBigImage.image(myStampImage, -myStartX*MySize,-myStartY*MySize,myStampImage.width*MySize,myStampImage.height* MySize); gBigImage.rotate(-theAngle- myDirection); gBigImage.translate(-theX*gStampRapportSize,-theY*gStampRapportSize); } } float Distance (float x1,float y1,float x2,float y2) { return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); }