Results 1 to 4 of 4
  1. #1
    anribalam is offline Member
    Join Date
    Mar 2012
    Posts
    2
    Rep Power
    0

    Default Bufferedimage to Byte[]

    Hi,

    i've found code by google to convert bufferedimage to byte[] :
    Java Code:
    private byte[] image_byte_data(BufferedImage image)
    {
        WritableRaster raster = image.getRaster();
        DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer();
        return buffer.getData();
    }
    and another one :
    Java Code:
    BufferedImage originalImage = ImageIO.read(new File("c:\\image\\mypic.jpg"));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write( originalImage, "jpg", baos );
    baos.flush();
    byte[] imageInByte = baos.toByteArray();
    baos.close();
    i want to get byte[] from bufferedimage, then do some process that may make values of byte[] changes.

    after that process, i'ill get new byte[] values, then i want to create new bufferedimage from that image and show it as image.
    which code is fit with my problem.
    and what difference between both above.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: Bufferedimage to Byte[]

    The former byte[] is the actual image.
    The latter byte[] is the jpg (ie compressed) image.

    The former is the one you want to use for manipulating an image.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    anribalam is offline Member
    Join Date
    Mar 2012
    Posts
    2
    Rep Power
    0

    Default Re: Bufferedimage to Byte[]

    thanks for reply,

    when i try getting byte[] with the first code above,
    i've got a huge byte[] in string.
    * i write the byte[] to file text,

    is it because with former code, i get raster data (contain Alpha, Red, Green, Blue color)?
    one pixel will represent as block of 4 byte of color.
    is it true?

    actually, i want to do some encryption process that encrypt plain-image to cipher-image.
    so i need convert plain-image to byte[].
    but after i encrypt the byte[], i must get byte[] that can be represent as image.
    is it possible right()?

    Thanks in advance

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: Bufferedimage to Byte[]

    The former is the image data that the JVM uses to display, so it is uncompressed (as you say).
    No point writing that to a file as it's not necessarily a recognised file format.

    Don't know anything about creating cipher images.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 1
    Last Post: 10-21-2011, 11:55 AM
  2. Read a bitmap byte by byte
    By cbr400aero in forum Java 2D
    Replies: 2
    Last Post: 10-18-2010, 11:42 PM
  3. Replies: 1
    Last Post: 04-21-2010, 02:28 AM
  4. Convert Byte [] to BufferedImage
    By Smily in forum Advanced Java
    Replies: 3
    Last Post: 04-28-2008, 05:54 PM
  5. BufferedImage to Byte
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-22-2008, 08:17 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
  •