Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i am having a bitmap image sent to me over tcp, then stores the data in a byte[] array called jacketBytes, but thenen when i try to make an image out of it using;

BufferedImage img = ByteArrayInputStream(bytes));
i get Nullpointerexception
so i started troubleshooting by writing out my byte array in different ways.
    FileOutputStream fos = new FileOutputStream(strFilePath);
System.out.println("total bytes: "+bytes.length);
for(int i =0; i < 56; i++){
System.out.print("0x"+bytes[i]+" ");
for(int i =0; i < 1000; i++){

the output i get from that is :
total bytes: 34928
0x52 0x50 0x52 0x68 0x51 0x54 0x48 0x52 0x48 0x49 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48

the first part 42 4D(0x52 0x50 0x52 0x68) is BM in ASCII just the way a bmp header is supposed to start.
what i cant figure out is what the rest if the data is! there is supposed to be 4 bytes containing the image data in bytes.
at least according to wikipedia wikipedia

The only documentation on how the data is sent to me is this:
NET/USB Jacket Art/Album Art Data
t-> Image type 0:BMP,1:JPEG
p-> Packet flag 0:Start, 1:Next, 2:End
xxxxxxxxxxxxxx -> Jacket/Album Art Data (valiable length, 1024 ASCII HEX letters max)

i manage to store it in a single byte Array but i do not know how to make it in to image data since it contains so much nulls!
Help appreciated!

You should probably encode your data in base 64.

Base64 in .Net framework?[^]

and have the proper header for such transfer.
Share this answer
I Solved it myself, thanks for the answer though. I got so frustrated when i solved it. the string i got was a hex string in ASCII so first i had to take the String pair by pair and then turn the pair i got into a Character. then i could use the new string and just encode it back to a byteArray and then it was a working image. Strange protocol i think.
Share this answer
Krillezz 22-Feb-12 3:06am    
Btw it is onkyos iscp protocol

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900