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

python - No exponential form of the z-axis in matplotlib-3D-plots -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -

Why does a .NET 4.0 program produce a system.unauthorizedAccess error on a Windows Server 2012 machine with .NET 4.5 installed? -