Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: displaying a jpeg image in memory

  1. #1
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default displaying a jpeg image in memory

    Spent the whole the evening googling and looking through java documentation via intellisence, and I could not find a solution for this problem at least without going through a whole lot of trouble

    I have an image in a byte array

    byte [] image;

    but the image has a jpeg format. I want to display the image without any reading or writing to the hard drive.

    Anyone knows how to do this? I have the standard libraries, approximately, and I am using Netbeans 5 IDE so far it really does not look possible.
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  2. #2
    Join Date
    Oct 2004
    Posts
    4,814
    Rep Power
    24

    Default

    use the BufferImage class to hold the image in memory.

    http://java.sun.com/j2se/1.3/docs/gu...image.fm3.html

  3. #3
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    Muchos thanks for the look up.

    Thanks too for the API library link

    I am checking it out know
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  4. #4
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    I was looking at the buffer image class and there is no support for jpeg format so I think I need a class that converts a jpeg array to a image buffer. If there is no functionlity for this then I will google a jpeg decompressor or decoder.

    Your link lead me to this Java Advanced Imaging API Home Page
    http://java.sun.com/products/java-media/jai/whatis.html
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  5. #5
    Join Date
    Oct 2004
    Posts
    4,814
    Rep Power
    24

    Default

    http://access1.sun.com/techarticles/...ps/JImage.html

    BufferedImage can be used to hold and to manipulate image data retrieved from a file. To display the image, you need to set up the Graphics2D rendering context and then call one of the Graphics2D rendering methods. The graphic elements are rendered off-screen to the BufferedImage and are then copied to the screen through a call to Graphics2D drawImage().

    BufferedImage bi = (BufferedImage) createImage(w, h);

  6. #6
    Join Date
    Oct 2004
    Posts
    4,814
    Rep Power
    24

    Default

    so basically this is what your looking for.


    File f = new File("duke.jpg");
    BufferedImage bufi = ImageIO.read(f);

  7. #7
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    Hand brake

    I cant't run this line
    img = getToolkit().getImage(JPEGText.class.getResource(" image.jpg"));
    from the first example with BufferedImage because img is already in Image (decompressed) format but I have an array in Jpg format (compressed) format

    Quote Originally Posted by crosswire
    I have an image in a byte array

    byte [] image;

    but the image has a jpeg format. I want to display the image without any reading or writing to the hard drive.
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  8. #8
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    I do not have this library
    import com.sun.media.jai.codec.*;

    I going look at the second example with it and download the library.
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  9. #9
    Join Date
    Oct 2004
    Posts
    4,814
    Rep Power
    24

    Default

    Then we load our GIF or JPEG into an Image object using the Applet method getImage()
    The code is contained within an Applet class therefore that method belongs to the Applet class. getToolkit() function is a method of any class inheriting from Component class. If you not using a onscreen component try the second method.

    File f = new File("duke.jpg");
    BufferedImage bufi = ImageIO.read(f);

  10. #10
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    getImage uses a string file name or a srting url, both of which are invalid in my case. The reason why I have an array is because I passed the array directly as a param for the applet. This was done by passing the image inline embedded in an html page without any urls or file paths to load

    The array in itself is a stream of bytes similar to a jpeg file but there is no jpeg file as the array is present in the applet only in memory already
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

Posting Permissions

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