×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    10

    sending captured image from j2me app to PC

    Hi,

    I'm developing an application that can capture image and then send it to j2se app on PC. The Bluetooth part is done and is working fine, but I'm unable to correctly save the image on the PC.

    In the midlet, I'm using this code to get the captured image:

    byte[] imageRaw = videoControl.getSnapshot("encoding=png");

    and then I'm sending this array of bytes to PC.
    In the j2se app, I'm using this code to create image:

    File outputfile = new File("pic.png");
    FileImageOutputStream fios = new FileImageOutputStream(outputfile);
    fios.writeChars(buf.toString()); // i'm receiving the data into StringBuffer
    fios.close();


    However, I'm unable to open pic.png afterwards.

    Can anyone help me please?

    Regards,
    Pedro

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: sending captured image from j2me app to PC

    Quote Originally Posted by pedron4 View Post
    However, I'm unable to open pic.png afterwards.
    What is happening over there in the code?
    Is there any exception?

    Please put the code always in the try-catch block..
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    10

    Re: sending captured image from j2me app to PC

    I meant that I'm unable to open the picture in some viewer, not in the j2se app. The FileImageOutputStream creates the .png file, there is no exception thrown. I guess it's just not in the right encoding.

    Btw, the FileImageOutputStream creates a .png file with size twice as big as the length of the array of bytes I'm sending from midlet.
    Code:
    File outputfile = new File("pic.png");
    FileImageOutputStream fios = new FileImageOutputStream(outputfile);
    fios.writeChars(buf.toString()); // i'm receiving the data into StringBuffer
    fios.close();
    When I'm using BufferedWriter, the size of image.png is the same as the length of the array of bytes I'm sending from midlet.
    Code:
    BufferedWriter bw = new BufferedWriter(new FileWriter(new File("image.png")));
    bw.write(buf.toString()); // i'm receiving the data into StringBuffer
    bw.close();
    Something tells me, that when the captured image has 0,5 MB, it should not have 1 MB after creating the same image from array of bytes in the PC.

    Pedro

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    10

    Re: sending captured image from j2me app to PC

    Well, I've figured it out.

    The problem was with the FileImageOutputStream.writeChars(String s) method. In J2SE API for this method, there is written
    For every character in the string s, taken in order, two bytes are written to the output stream....
    So I just changed it to writeBytes(String s) method, and it works.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    20

    Re: sending captured image from j2me app to PC

    I know is an old post, but this may help someone. If you are receiving the data using a text channel, rather than binary channel, you should use Base64 format to encode the image byte arrray. I wrote a post about taking a snapshot and sending it to a server over HTTP POST in Base64 format, may be it helps:

    http://www.java-n-me.com/2011/02/tak...coding-in.html

    bye.

Similar Threads

  1. [moved] J2me polish background image problem
    By poojs in forum Mobile Java Media (Graphics & Sounds)
    Replies: 3
    Last Post: 2009-05-25, 11:42
  2. sending pic from j2me app
    By praran910 in forum Mobile Java General
    Replies: 1
    Last Post: 2008-09-29, 16:28
  3. Phone > PC app > web — need pointers for the PC app
    By kwameferreira in forum Mobile Java Games
    Replies: 2
    Last Post: 2007-01-04, 18:18
  4. Sending file(s) from PC to S60 mobiles using J2ME
    By alam.sher in forum Bluetooth Technology
    Replies: 1
    Last Post: 2006-12-22, 14:10
  5. Nokia Image Converter
    By davidpurdie in forum General Development Questions
    Replies: 0
    Last Post: 2004-02-18, 15:31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •