Converting binary jpeg into BITMAP
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: Converting binary jpeg into BITMAP

  1. #1
    Join Date
    Mar 2010
    Posts
    48

    Converting binary jpeg into BITMAP

    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.

  2. #2
    Join Date
    May 2010
    Posts
    9

    Re: Converting binary jpeg into BITMAP

    checkout the System.IO.Compression namespace

  3. #3
    Join Date
    Mar 2010
    Posts
    48

    Re: Converting binary jpeg into BITMAP

    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.

  4. #4
    Join Date
    May 2010
    Posts
    9

    Re: Converting binary jpeg into BITMAP

    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>

  5. #5
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Converting binary jpeg into BITMAP

    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 - http://the-angry-gorilla.com/

  6. #6
    Join Date
    Mar 2010
    Posts
    48

    Re: Converting binary jpeg into BITMAP

    I don't mind about quality loss.

  7. #7
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Converting binary jpeg into BITMAP

    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.
    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 - http://the-angry-gorilla.com/

  8. #8
    Join Date
    Mar 2010
    Posts
    48

    Re: Converting binary jpeg into BITMAP

    Though I'm not doing this for a single image. Thousands of images are being created, and I want them all stored in a single file. Hence, why I'm converting them to binary. I do not want thousands of jpegs in a folder, doesn't look very neat.

  9. #9
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,836

    Re: Converting binary jpeg into BITMAP

    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.

  10. #10
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Converting binary jpeg into BITMAP

    Quote Originally Posted by ADT_Clone View Post
    Though I'm not doing this for a single image. Thousands of images are being created, and I want them all stored in a single file. Hence, why I'm converting them to binary. I do not want thousands of jpegs in a folder, doesn't look very neat.
    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?
    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 - http://the-angry-gorilla.com/

  11. #11
    Join Date
    Apr 2011
    Posts
    20

    Question Re: Converting binary jpeg into BITMAP

    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

  12. #12
    Join Date
    May 2007
    Posts
    1,546

    Re: Converting binary jpeg into BITMAP

    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...
    www.monotorrent.com 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.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center