×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    12

    Sending image file via bluetooth

    Can a phone with jsr-75 send an image file to another phone without jsr-75 via bluetooth?

  2. #2
    Registered User
    Join Date
    Jun 2007
    Posts
    12

    Re: Sending image file via bluetooth

    i figured out i have to convert the image to byte array before trasnferring to the non jsr75 phone. i will have to save it on rms. however, if i were to send the image back to the jsr75 phone, i cant save the image as jpg file.

    this is what i did:
    Code:
    int[] imgRgbData = new int[width * height];
    
    img.getRGB(imgRgbData, 0, width, 0, 0, width, height);
    
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);
    dos.writeUTF(imgType);
                                        
    for (int i = 0; i < imgRgbData.length; i++) {
        dos.writeInt(imgRgbData[i]);
    }
                                        
    byte[] imageBytes = baos.toByteArray();
    
    
    FileConnection fc = (FileConnection) Connector.open(url, Connector.READ_WRITE);
    if(!fc.exists()) {
        fc.create();
        DataOutputStream out;
        out = fc.openDataOutputStream();
        out.write(imageByte, 0, imageByte.length);
        out.flush();
        out.close();
        fc.close();
    }
    the jpg file is created but i can't view the image. is there anything that i missed out? thanks.

  3. #3
    Nokia Developer Expert
    Join Date
    Jun 2005
    Posts
    923

    Re: Sending image file via bluetooth

    It seems are losing binary image data using this code.

    If you're reading the image from an InputStream (image located in the .jar file for example), just read the bytes and write them out to the OutputStream you got from the Bluetooth connection. Use pure InputStream and OutputStream classes. If you use DataInput/Output-derived classes, and start mixing write(byte[] b) with readInt() you will get into a lot of trouble.

    If you're reading the image from camera capture, just get the byte array returned by getSnapshot() and write it out to the Bluetooth connection's OutputStream using write(byte[] b).

    Summary: just use raw input/output streams, no need to get RGB data or use specialized DataInput/Output stream classes. If you are still in doubt, just convert the image to String using Base64-encoding and read it at the other side.

    []s
    Daniel

  4. #4
    Registered User
    Join Date
    Jun 2007
    Posts
    12

    Re: Sending image file via bluetooth

    thanks for the reply.

    if i want to store the Image object to the RMS, i have to convert the image to byte[]. So to convert Image to byte[], do I do something like this?

    Code:
    byte[] imgBytes= image.toString().getByteArray();
    I tried this method and when I retrieve the byte[] to convert back to Image object, i got IllegalArgumentException.

    Code:
    Image image = Image.createImage(imgBytes, 0, imgBytes.length);
    Have I not done it correctly?

  5. #5
    Nokia Developer Expert
    Join Date
    Jun 2005
    Posts
    923

    Re: Sending image file via bluetooth

    Code:
    byte[] imgBytes= image.toString().getByteArray();
    This is where you're losing data. toString() will return something like "java.lang.Object@912391" and that's all you'll end up getting in the byte array.

    What kind of image are you trying to save, exacly? Taken from the camera, read from the file system or created as a mutable image ("Image.createImage()") ?

    In the first two cases you'll have access to the InputStream, so use it. In the last case, you still can use the getRGB and then you'll have a int[] object. Create a DataOutputStream to the other device and write the integers. On the other side, read the integers into a int[], convert this to a byte[] using the ByteArrayOutputStream like you did below, and save it to the RMS. But please don't try to load it back as a jpg file because it's NOT a jpg file: it's pure raw RGB data so it can only be seen by the midlet application, by using Image.createRGBImage() method.

    Daniel

  6. #6
    Registered User
    Join Date
    Jun 2007
    Posts
    12

    Re: Sending image file via bluetooth

    meaning there is no way to save it as jpg file?

  7. #7
    Nokia Developer Expert
    Join Date
    Jun 2005
    Posts
    923

    Re: Sending image file via bluetooth

    If you create a mutable Image using Image.createImage(int,int) then no, there's no way to save it as jpeg, as it's not a jpeg file but RGB data instead.

    Daniel

  8. #8
    Registered User
    Join Date
    Jun 2007
    Posts
    12

    Re: Sending image file via bluetooth

    can the RGB data be saved into a file? or any way (not using mutable image) to save as jpg file?

Similar Threads

  1. Sending File From mobile to PC using bluetooth and J2me
    By abed_elm in forum Bluetooth Technology
    Replies: 1
    Last Post: 2006-03-09, 08:19
  2. Delete a file after bluetooth sending
    By cqq in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2005-07-24, 05:27
  3. Bluetooth sending file linking faild
    By sblider in forum Symbian Networking & Messaging (Closed)
    Replies: 8
    Last Post: 2004-03-12, 17:34
  4. Sending .jpg file from phone to PC
    By ja_calulot in forum Symbian
    Replies: 0
    Last Post: 2003-09-06, 09:34
  5. Sending Image file to External Application
    By preneeth in forum Smart Messaging
    Replies: 1
    Last Post: 2003-03-23, 21:35

Posting Permissions

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