Results 1 to 4 of 4
  1. #1
    Smily is offline Member
    Join Date
    Apr 2008
    Posts
    2
    Rep Power
    0

    Default Convert Byte [] to BufferedImage

    I was wondering if any can show me how to create a bufferedImage from a byte []. I saw an example on the forums here that converts a bufferedImage to a byte []. So I thought someone might know. Thanks


    The following was the code I found
    Java Code:
    private byte[] image_byte_data(BufferedImage image)
    {
        WritableRaster raster = image.getRaster();
        DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer();
        return buffer.getData();
    }

  2. #2
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    dont worry newbie, we got you covered.

  3. #3
    Smily is offline Member
    Join Date
    Apr 2008
    Posts
    2
    Rep Power
    0

    Default

    Thanks for the response, however there is one particular part I'm stuck at. Is there a way to convert a byte [] to an bufferedimage without knowing the original height of the Image. For example, you take a bufferedimage convert it to byte [], then you store it into a database. Some point later you come back and just want to reconstruct the image using the byte array.

    So my question would be, before I convert a bufferedimage to a byte [] should I also save the length and width of the image into the database so that I can reconstruct the image back up? The reason I'm asking this is because the images are all of different size.

  4. #4
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    "should I also save the length and width ?"
    Yes. byte[] only gives the pixels.
    dont worry newbie, we got you covered.

Similar Threads

  1. Byte Values
    By javaplus in forum New To Java
    Replies: 1
    Last Post: 06-23-2008, 12:08 AM
  2. using Byte arrays
    By mew in forum New To Java
    Replies: 2
    Last Post: 01-30-2008, 03:54 AM
  3. BufferedImage to Byte
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-22-2008, 08:17 PM
  4. int to byte
    By ravian in forum New To Java
    Replies: 1
    Last Post: 01-13-2008, 07:22 PM

Posting Permissions

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