text: Okay, following on from my other post, I managed to save a standard Bitmap into a file in Binary Form. The problem I am now having though is the file becomes very large very fast. My solution was to save it as a jpeg, then take the bytes of that and put it into the file.
  The problem I have run into is when I retrieve these bytes, I can not convert it back into a standard Bitmap. Any suggestions on how I can do this?
  EDIT: Just to summarise, I want to: Convert bitmap to a compressed format -> Convert to byte array -> Retrieve byte array -> Convert compressed format back to a Bitmap.
  I know how to convert into a byte array, I just need to be able to reverse the process.
  Last edited by ADT_Clone; May 3rd, 2010 at 01:48 AM.
  This won't work because it compresses it at the end. I need each bitmap added to be compressed so the size of the temporary file doesn't become too large.
  Actually, I believe the namespace includes streaming compression. If you need each bitmap to be compressed separately then you could create a header for each compressed bitmap.
  example....
  Code:
  <Bitmaps>
  <Bitmap MyDescriptionAttribute="Useful_Attribute_Info">
  Encrypted Bitmap Info
  </Bitmap>
  </Bitmaps>
  <Bitmaps>
  <Bitmap MyDescriptionAttribute="Useful_Attribute_Info">
  Encrypted Bitmap Info
  </Bitmap>
  </Bitmaps>
  You do realize that JPEG compression is lossy, right? It is a one way street, you will never be able to get back the original image.
  If you liked my post go ahead and give me an upvote so that my epee.... ahem, reputation will grow.
  Yes; I have a blog too -
  I don't mind about quality loss.
  Right, but what I am saying is that you are not going to get back the same image that you had before you compressed it. I mean really, this problem is as simple as this contrived example:
  Code:
  void SaveAsJPEG( Bitmap b, string path )
  {
  b.Save( path, ImageFormat.Jpeg );
  }
  Bitmap Retrieve( string path )
  {
  return new Bitmap( path ); // loads jpeg files just fine
  }
  My point is that I don't see what your problem really is. Just save the thing as a Jpeg and the compression is done for you. When you retrieve it from disk you need only pass the file path top the Bitmap constructor, the Bitmap class can load a jpeg with no problem.
  void SaveAsJPEG( Bitmap b, string path )
  {
  b.Save( path, ImageFormat.Jpeg );
  }
  Bitmap Retrieve( string path )
  {
  return new Bitmap( path ); // loads jpeg files just fine
  }.
  I assume that you are aware that a jpeg is stored as binary data but just in case. The only difference here is you are wanting to put several images in one file.
  Another option of course may be to save them as images be it jpeg or bmp and zip them up into a single zip file. Would likely take a bit more processor but would seem like a simple way to get them into and back out of the single file as well as keeping the file size reasonably small.
  Always use [code][/code] tags when posting code.
  Originally Posted by ADT_Clone.
  Your users are watching a directory and don't like how it looks? I don't see multiple files as a problem, just create a subfolder in your working directory and name it "images" or something. Why would a user care?
  Have you solved your problem?
  I would like to do the same thing, that is to compress every bitmap frame without saving it into a jpg file and at the end of my process chain, show the compressed data as image within a picture box, for example.
  Do you know now how to achieve it?
  The byte array, where raw image data lies in has got fixed dimensions, but if you compress the data, you cannot predict how big the byte array should be for the compressed bytes, right? So how to handle it? Some ideas?
  Thanks
  How do you plan on updating a single 10 gigabyte 'image' file if you want to delete one image from the middle?
  Seriously, this is an insane decision if it's purely for aesthetic purposes because you dislike seeing more than 1 file in your folder... For all your .NET bittorrent needs
  NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.
  Forum Rules