Discussion Board

Results 1 to 8 of 8
  1. #1
    Regular Contributor
    Join Date
    Jan 2006
    Location
    India
    Posts
    87

    Converting image object into byte array

    Hi,
    I have one image object created from the resource folder directly not by using getclass.getResourceStream();

    i.e.
    img=Image.createImage("/test.png");

    How can i convert this into byte array..

    i knew that one function is there in graphics class called getRGB()
    but it is returning in interger array....

    If need to send this image object in RMS or server what should i do................
    Thanks & Regards
    kannan
    [kamalinfo2k2@yahoo.com]

  2. #2
    Registered User
    Join Date
    Jun 2006
    Posts
    259

    Re: Converting image object into byte array

    Hi,

    Check this link http://developer.sonyericsson.com/si..._java_0502.jsp may be useful.

    Cheer's

  3. #3
    Regular Contributor
    Join Date
    Jan 2006
    Location
    India
    Posts
    87

    Re: Converting image object into byte array

    thanks marvik_34...
    Thanks & Regards
    kannan
    [kamalinfo2k2@yahoo.com]

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    25

    Re: Converting image object into byte array

    @ marvik_34 the above link not working pls provide a working link or else post the code.

    Thanks
    Sasi Kumar T

  5. #5
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: Converting image object into byte array

    Hi ,

    You mentioned you are able to get the int[] array . The take the ByteArrayOutputStream and loop through your byte array and write your integer's using there is method in ByteArrayOutputStream write(int);

    After that you can take byte[] from the ByteArrayOutputStream using toByteArray()

  6. #6
    Super Contributor
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: Converting image object into byte array

    either that or encode it.
    there is a png encoder on the wiki, and a jpeg encoder here http://ce.sharif.edu/~p_amini/j2me/JPEG_Encoder

    Also, why don't you simply load the file using getClass.getResourceStream(); ? you would easily get a byte[] from that.

  7. #7
    Registered User
    Join Date
    Oct 2007
    Posts
    25

    Re: Converting image object into byte array

    hi,

    I am using camera to capture and then store in RMS by int[] with an ID and retrieve it and create an Image object using createRGB and convert the image object into byte [] and send to servlet and store in MySQL as BLOB but it's not show the image ,if i send an image(by bytes) to servlet after capture without store in RMS it's shows in MySQL . i don't know where i made mistake, pls provide a solution .

    Thanks
    sasi Kumar T

  8. #8
    Super Contributor
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: Converting image object into byte array

    Quote Originally Posted by sasikumar31 View Post
    create an Image object using createRGB and convert the image object into byte []
    Kumar, the snapshot you get from the camera is not an RGB array, to make an image out of it, you need to use createImage(byte[] imageData, int imageOffset, int imageLength) (http://java.sun.com/javame/reference...eateImage(byte[], int, int) ), then as the snapshot is a byte[], it is what you need to send to your servlet, not converting the Image object

Similar Threads

  1. how to cut some part of Image
    By mshouab in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2006-08-04, 09:05
  2. hw will get byte array of an image -urgent
    By rak_eshz in forum Mobile Java General
    Replies: 5
    Last Post: 2006-06-13, 09:40
  3. hw will get byte array of an image -urgent
    By rak_eshz in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2006-05-29, 16:15
  4. Reading from Image Object to a Byte Array
    By Ghouse in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2003-06-13, 18:02
  5. Loading images from byte array on 6130i
    By enlightment in forum Mobile Java General
    Replies: 2
    Last Post: 2002-06-05, 19:44

Posting Permissions

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