backspaces
Junior Member
Offline
Posts: 66
|
Re: saveFrame hangs, files huge!
Reply #2 - Mar 11th, 2006, 7:19pm
Thanks for the idea, uoou: when I make the number of cars 0, the saveFrame works fine! It's even pretty fast.
BTW: Here's the original applet without the frameSave() code: http://backspaces.net/files/Roads/applet/
If I set the number of cars to 1, it still works! Weirder and weirder. Still pretty fast.
If I set the number of cars to 100, it just works .. but very, very slowly. The simulation itself runs quite fast (6fps even with 15,000 cars) as you can see from running the applet.
So it looks like the problem has to do with the cars? Or possibly with any significant change at all in the image?
BTW: I also found that this behavior/bug is also true with saveBytes .. I tried converting the image to jpg using a previously posted SaveJpg method, and it also worked with 1, 10, very slowly with 100 and so on. Its a bit slower anyhow due to the additional computation.
Owen
import com.sun.image.codec.jpeg.*;
void SaveJpg(String fname){ ByteArrayOutputStream out = new ByteArrayOutputStream(); BufferedImage img = new BufferedImage(width, height, 2); img = (BufferedImage)createImage(width, height); loadPixels(); for(int i = 0; i < width; i++) { for(int j = 0; j < height; j++) { int id = j*width+i; img.setRGB(i,j, pixels[id]); } } try{ JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(img); } catch(Exception e){System.out.println(e);} byte [] a = out.toByteArray(); saveBytes(fname, a); }
|