how to write and read pgm p5 file in java -


i want read pgm file. kept image content in byte array. when accessed pixels, see values negative. so, applied "& 0xff" each byte. hope ok when write file, isn't same original image.

how can read , write pgm p5 file?

int = bytearray[index] & 0xff; //reading writer.write((char)(i)); //bufferedwriter     

keep in mind p5 format binary. using writer , cast value char. text, not binary data.

instead, use outputstream , write value in i directly stream.

int = bytearray[index] & 0xff; // reading stream.write(i); // outputstream  

ps: if don't feel implementing pgm format yourself, have created imageio plugin netpbm formats (pnm) use. it's open source (bsd license).


Comments

Popular posts from this blog

java - HTTP Status 500 - An exception occurred processing JSP page /second.jsp at line 15 -

php - Using str_replace to translate a MySQL Table in html -

asp.net mvc - Cannot display error message on Editor or EditorFor -