Scusa il ritardo nella risposta ma avevo lasciato il sorgente su ubuntu.
Ecco il codice completo
codice:
import java.io.*;
import java.util.Arrays;
class ImagePpm {
private byte data[];
private int width,height;
ImagePpm(int w, int h) {
width = w;
height = h;
data = new byte[3+(width*height*3)];
Arrays.fill(data,(byte)0);
}
void setPixel(int x,int y, int r, int g, int b) {
if(x >=0 && y>=0 && x<=width && y<=height) {
data[3*(x+y*width) ] = (byte)(r&0xff);
data[3*(x+y*width)+1] = (byte)(g&0xff);
data[3*(x+y*width)+2] = (byte)(b&0xff);
}
}
void saveImage(String name) throws IOException {
PrintStream bos = new PrintStream(new FileOutputStream(name+".ppm"));
bos.println("P6\n"+"#Immagine generata da ImagePpm di RootkitNeo\n"+width+" "+height+"\n255\n");
/*for(int i=0; i<data.length; i++) {
bos.println(data[i]);
}*/
bos.write(data);
//bos.flush();
bos.close();
}
}
class Ppm {
public static void main(String args[]) throws IOException {
int w=1024,h=768;
ImagePpm ppm = new ImagePpm(w,h);
for(int i=0; i<w; i++) {
ppm.setPixel(i,h/2,255,0,0);
}
for(int j=0; j<h; j++) {
ppm.setPixel(w/2,j,255,0,0);
}
ppm.saveImage("test");
}
}
Ora provo a modificare lo stream sul mio e a guardare bene il tuo source