How to read in BMP as bytes

pushVTEC

Senior member
Aug 30, 2003
265
0
0
Does anyone know to read in a bmp file as bytes? I'm working on a compression program and I'm having problems just getting the file in as bytes. I'm writing the program in java. Any ideas?
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Not quite like any other file. java.io makes the distinction between binary and text streams. Anything dealing with text is generally postfixed "Reader" or "Writer". Anything dealing with binary data is generally postfixed "InputStream" or "OutputStream". In this case you should be using a FileInputStream, rather than a FileReader. The difference is that on *nix systems the FileReader will convert "\r\n" to a single '\n' and on Windows machinces it will convert '\n' to "\r\n". And something similarly odd on macs. Of course, those ascii digits have nothing to do with lines ending in bitmaps.

Just as an aside, if you've ever transfered a picture via ftp while in text mode and it came out with funny colours, that's what happened.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: kamper
Not quite like any other file. java.io makes the distinction between binary and text streams. Anything dealing with text is generally postfixed "Reader" or "Writer". Anything dealing with binary data is generally postfixed "InputStream" or "OutputStream". In this case you should be using a FileInputStream, rather than a FileReader. The difference is that on *nix systems the FileReader will convert "\r\n" to a single '\n' and on Windows machinces it will convert '\n' to "\r\n". And something similarly odd on macs. Of course, those ascii digits have nothing to do with lines ending in bitmaps.

Just as an aside, if you've ever transfered a picture via ftp while in text mode and it came out with funny colours, that's what happened.

Forgot about that :eek:

<-- Goes and hides for his Java sins.