×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Super Contributor
    Join Date
    Jan 2008
    Location
    Amravati, India
    Posts
    546

    Display jpg image from byte array

    I have a jpg image in a byte array. (My application will get it from network into a byte array)
    I want to display it.
    Image.createImage(buf, 0, buf.length)
    throws exception which means it doesn't support jpg...
    how to display it...

    Thanks in advance

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Display jpg image from byte array

    What is the device?

    If the device doesn't support jpegs, then the only way is to write your own decoder... no small task.

  3. #3
    Super Contributor
    Join Date
    Jan 2008
    Location
    Amravati, India
    Posts
    546

    Re: Display jpg image from byte array

    Its Nokia E61i and I think it supports jpg images...
    anyways... do u know any good jpg decoder for J2ME

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Display jpg image from byte array

    Try loading a jpeg from the application's JAR:

    Code:
    Image jpeg = Image.createImage("my.jpg");
    See if that works. Possibly the data you have in the byte array is not as valid as you think.

  5. #5
    Super Contributor
    Join Date
    Jan 2008
    Location
    Amravati, India
    Posts
    546

    Re: Display jpg image from byte array

    Although I haven't tried, but I have seen discussions on some forum that this thing works:
    Code:
    Image jpeg = Image.createImage("my.jpg");
    but if you createImage with byte array then it doesn't work...

    Also,
    Quote Originally Posted by grahamhughes View Post
    Possibly the data you have in the byte array is not as valid as you think.
    That's not the case...same code is working fine if I send png image from the server...


    it would be great if you suggest a good jpg decoder for J2ME...

  6. #6
    Super Contributor
    Join Date
    Jan 2008
    Location
    Amravati, India
    Posts
    546

    Re: Display jpg image from byte array

    I have tried this JPEGDecoder:
    http://webuser.hs-furtwangen.de/~dersch/
    My images are now displayed well with the help of this decoder.
    But it is consuming 524 KB of heap memory...
    I want a memory decoder which should consume less than 50 KB of heap memory...
    Please suggest me a good jpeg decoder...

    Thanks in advance

  7. #7
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Display jpg image from byte array

    I think you're lucky to find a decoder at all...

    How big is the image (file size and pixel size)?

    How do you know it's using 524k?

  8. #8
    Super Contributor
    Join Date
    Jan 2008
    Location
    Amravati, India
    Posts
    546

    Re: Display jpg image from byte array

    Quote Originally Posted by grahamhughes View Post
    I think you're lucky to find a decoder at all...
    That means nobody will suggest me a decoder

    Quote Originally Posted by grahamhughes View Post
    How big is the image (file size and pixel size)?
    File size: 1 KB to 4 KB
    Image size: 18 x 25 pixels to 100 x 100 pixels

    Quote Originally Posted by grahamhughes View Post
    How do you know it's using 524k?
    Case 1:
    Code:
    JPEGDecoder JPEGDecoderObject = new JPEGDecoder();
    System.gc();
    System.out.println("Free memory is " + String.valueOf(RuntimeObject.freeMemory() / 1024) + "KB");
    Case 2:
    Code:
    //JPEGDecoder JPEGDecoderObject = new JPEGDecoder();
    System.gc();
    System.out.println("Free memory is " + String.valueOf(RuntimeObject.freeMemory() / 1024) + "KB");
    Memory consumed by JPEGDecoderObject = Case 2 - Case 1

  9. #9
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Display jpg image from byte array

    Hmmm... you're right!

    Good grief. The problem is that the Huffman tables are all fixed sizes. This line:

    Code:
    private int HuffTab[][][] = new int[4][2][MAX_HUFFMAN_SUBTREE * 256];
    creates an array of 400k. And this:

    Code:
    int V[][][][] = new int[4][2][16][200];
    is another 100k. The other arrays amount to about 30k.

    I don't think this can work in 50k, but if these arrays are dynamically sized, you should be able to cut this down a lot.

  10. #10
    Super Contributor
    Join Date
    Jan 2008
    Location
    Amravati, India
    Posts
    546

    Re: Display jpg image from byte array

    Basically I want to transfer images from my server and display it on phone
    I want least data transfer to occur
    Do you know any good image compression algorithm/format which results into 100 x 100 pixels image to be converted into less than 5KB and which consumes heap memory less than 50KB...

  11. #11
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Display jpg image from byte array

    You can use PNG.. how small you will get depends on what is in the image. If you reduce the number of colours, and use PNGOUT you will get the size down.

    You should be able to modify that code to use less memory, and decode a JPEG.

  12. #12
    Super Contributor
    Join Date
    Jan 2008
    Location
    Amravati, India
    Posts
    546

    Re: Display jpg image from byte array

    Quote Originally Posted by grahamhughes View Post
    You can use PNG
    My images consists of lots & lots of colors. So, size of 100 x 100 pixels PNG image is in the range 18KB to 22KB which is very very high... I want less than 5KB...

    Quote Originally Posted by grahamhughes View Post
    You should be able to modify that code to use less memory, and decode a JPEG.
    Really?
    I didn't read jpeg compression-decompression algorithm...
    How can I manage without HuffTab... I don't want heap consumption to go beyond 50KB at any point of time during decoding...
    I can think of only one way... don't pre-calculate the HuffTab. Instead, calculate the value as and when it is required... but this will deteriorate the performance I think...
    Last edited by arpit2agrawal; 2009-01-04 at 23:50.

  13. #13
    Super Contributor
    Join Date
    Jan 2008
    Location
    Amravati, India
    Posts
    546

    Re: Display jpg image from byte array

    Some years ago I had read wavelet compression algorithm which has negligible memory footprint.
    Today, using Corel Draw I converted my image to .wi (Wavelet Compressed Bitmap) file which gives me reduction in size up to 4KB and quality at par with jpeg images.
    I hope decoding .wi file will also consume negligible heap memory.
    So, I think one can use .wi image file format to send images from server and display on phone
    I want .wi image decoder for J2ME
    If anyone knows then please post here...
    Last edited by arpit2agrawal; 2009-01-07 at 01:15.

  14. #14
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Display jpg image from byte array

    u must be doing something wrong....
    a 100x100 pixels PNG image cant be 18K to 22K...
    try to convert the jpeg images to PNG 8 bit on server side and send those to ur mobile...
    U are mentioning many colors and so, so some quality degradation will occure when converting them to PNG 8 bit, but nothing to worry about, cause u alsways have to keep in mind its a 100x100 pixel picture which will be shown on a mini-screen (mobile) so nobody will notice the difference... most probably u are creating 32 or 24 bit PNG's now, try to cut that down to 8 bit...

  15. #15
    Super Contributor
    Join Date
    Jan 2008
    Location
    Amravati, India
    Posts
    546

    Re: Display jpg image from byte array

    I tried with 8 bit PNG. But the quality is degraded so much that it cannot be tolerated.
    Please note that some of the images contain even photos of human being
    So, 24 bit PNG will only do. But it has very very less compression ratio in the range 1.15:1 to 1.3:1
    I want compression ratio at least 3:1 or even more than that
    I tried Wavelet Compressed Bitmap and it gives me compression ratio more than 3:1 and that too without degrading quality much
    I just want a decoder of .wi files (Wavelet Compressed Bitmap) for J2ME

Similar Threads

  1. modifying image on display in canvas
    By aqibarain in forum Mobile Java General
    Replies: 1
    Last Post: 2007-11-30, 09:01
  2. Error when trying to create image from Byte array
    By chordfone in forum Mobile Java Media (Graphics & Sounds)
    Replies: 0
    Last Post: 2007-11-16, 00:34
  3. Display JPG image
    By Asif Nazir in forum Symbian User Interface
    Replies: 4
    Last Post: 2007-10-05, 10:44
  4. Image Problem
    By Spider_Eg in forum Mobile Java General
    Replies: 2
    Last Post: 2007-01-30, 13:52
  5. simple script to display rgb image
    By gojkoa in forum Symbian
    Replies: 1
    Last Post: 2005-11-21, 09:33

Posting Permissions

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