• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Encoding/decoding problem

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 56
Android Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic