Results 1 to 8 of 8

Thread: [2005] extracting multiple images from file

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    Question [2005] extracting multiple images from file

    I am trying to extract images from a dat file that contains more then one image. So far I am successful at getting the first image but that is all. My question is how can you loop through the bytes and tell where the current image ends and the next image begins. I am using MemoryStream to load the bytes and Image.FromStream to get the image.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] extracting multiple images from file

    The file format should be such that it tells you how many bytes each object it contains is. One example of how that could be done is for the first 8 bytes to represent the number of bytes for the first image. You read the first 8 bytes, convert that to a number, then read that many bytes. Now you know that the next 8 bytes contains the number of bytes in the next image, etc. If the file hasn't been written in a format like this then there is no way to know. Do you know the format of this file you're reading? We certainly don't.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    Re: [2005] extracting multiple images from file

    I should have uploaded the file for anyone to look at. Here it is.
    Last edited by zalez; Jul 24th, 2007 at 04:32 PM.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    Re: [2005] extracting multiple images from file

    How can I read a certain number of bytes and convert it to a number? Like the example given, read the first 8 bytes then convert it to a number?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] extracting multiple images from file

    vb Code:
    1. Dim offset As Integer = 0
    2. Dim count As Integer = 8
    3. Dim buffer(count - 1) As Byte
    4. Dim byteCount As Long
    5.  
    6. myFileStream(buffer, offset, count)
    7.  
    8. byteCount = BitConverter.ToInt64(buffer, 0)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] extracting multiple images from file

    Note that once you have executed that code you know that the next byteCount bytes contain the data for the first image. You'd advance the offset by 8 and start reading. Once you've read those byteCount bytes you know that you've read the entire image. If there is more data in the file then you can read the next 8 bytes to see how big the next image is and so on.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    Re: [2005] extracting multiple images from file

    jmcilhinney, I changed my attachment a few posts up, to a text file of the files that I am working with. Do you mind taking a look at it and see what you think about reading this and extracting the images?

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] extracting multiple images from file

    If explained the principles. It's now up to you to implement them.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Click Here to Expand Forum to Full Width