Results 1 to 4 of 4
  1. #1
    salmontres is offline Member
    Join Date
    Dec 2011
    Posts
    30
    Rep Power
    0

    Default Going from byte[] to Jpeg on disk

    Hi everyone,

    I want to go from an array of bytes to a file written on disk. I found some ways to do this online, but they were all doing a somewhat roundabout way. (They set up a Graphics2d object to draw the image, pass it through a RenderedImage object, then use ImageIO.write class from the standard IO methods to get it on disk. Is this the best way to do this? Has anyone else found a good, efficient way to go from an array of bytes to a jpeg or gif on disk?

    (Also, I should note that I'm on Java 6 and cannot currently upgrade...)

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,513
    Rep Power
    25

    Default Re: Going from byte[] to Jpeg on disk

    I want to go from an array of bytes to a file written on disk
    There are several write() methods that take an array of bytes as source for what is written. Which classes have you tried?
    Do you have code where you tried to do it that did not work? If so, can you post the code and describe the problems you are having with it?

  3. #3
    salmontres is offline Member
    Join Date
    Dec 2011
    Posts
    30
    Rep Power
    0

    Default Re: Going from byte[] to Jpeg on disk

    Thanks Norm. The code is actually quite convoluted, so I'll show my patched up solution. It all seems to be working now!

    //Write the picture to disk.
    BufferedOutputStream buff_out = new BufferedOutputStream(new FileOutputStream(file_for_cache));
    buff_out.write(arr);
    buff_out.close();

    I was pretty amazed at how little lines of code were actually required!

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,513
    Rep Power
    25

    Default Re: Going from byte[] to Jpeg on disk

    Mark it as solved if it's working and you have no more questions.

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. Scaling a JPEG
    By ScottVal in forum Advanced Java
    Replies: 5
    Last Post: 03-21-2009, 08:47 PM
  5. Replies: 1
    Last Post: 07-04-2008, 05:39 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
  •