[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.
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.
Re: [2005] extracting multiple images from file
I should have uploaded the file for anyone to look at. Here it is. :blush:
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?
Re: [2005] extracting multiple images from file
vb Code:
Dim offset As Integer = 0
Dim count As Integer = 8
Dim buffer(count - 1) As Byte
Dim byteCount As Long
myFileStream(buffer, offset, count)
byteCount = BitConverter.ToInt64(buffer, 0)
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.
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? :)
Re: [2005] extracting multiple images from file
If explained the principles. It's now up to you to implement them.