• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Encoding/decoding problem

 
zainu Mehmood
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

Need your help again.I am getting byte[] from onPreviewFrame(byte[] data, Camera arg1).Now i am transferring each frame through TCP to my System and then write a JPG file with that byte[].But when i open this JPG file it says that invalid JPG file.Moreover,when i send the same byte [] from PictureCallback jpegCallback = new PictureCallback() method and then write a JPG file on my PC ,it works fine.

I know its a kind of encoding issue,actually byte[] which i get from onPreviewFrame is byte array of compressed image data.

I can only transfer this byte array of compressed image data through TCP from my Phone to PC.But i want to decode this data once i get this on PC.Can you guys please help me how should i proceed.

I would be very grateful for any kind of help.

Best regards,
ZA
 
Misha van Tol
Ranch Hand
Posts: 56
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a thought, did you use setPreviewFormat(int) to set the correct (JPEG) format?
 
zainu Mehmood
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Misha,
Thanks for the reply.Yes i did use parameters.setPreviewFormat(ImageFormat.JPEG);But it doesn't change anything,even after setting this PreviewFormat to JPEG,it returns integer which is against NV21 format instead of JPEG when i call parameters.getPreviewFormat ().

 
Misha van Tol
Ranch Hand
Posts: 56
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a tough one, I've tried it over here but got the same result. After setting setPreviewFormat to JPG it does return other data but it's definitely not JPEG.
I guess you'll have to convert it yourself, first to bitmap data and then compress it to JPEG ( myBitmap.compress(CompressFormat.JPEG, 75, fos); )

 
zainu Mehmood
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Misha,
I am using following code



and then writing this baos to sd card.But its still not a JPG file .


 
Misha van Tol
Ranch Hand
Posts: 56
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll take a closer look at it. In my emulator the preview is only in NV16 format so the YuvImage doesn't work.
A disadvantage of YuvImage is that is API 8, so it's not working on 2.1 devices and lower.
 
zainu Mehmood
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I got it working now .But now i have got another strange problem ;).

I am doing two things with the byte array of this JPG image using following code of lines


here i am storing the image on sd card as well as sending that byte array through tcp to on my PC.Now image that store on sd card is just perfect but image that receive on my PC is whole black and its so irritating.

But anywaz thanks a lot for your help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic