Extracting image from binary file

J

jeffotn

Hi,

I have access to a binary file that contains 1 or more images. I am
trying to access the images in java so that I can extract them and
place them in a directory. I know the file is in little-endian format
and I used com.mindprod.ledatastream.LEDataInputStream to read it. I
the first line is ascii and tells me the length of the blob, but I am
unable to extract it and parse out the images.
I am a green horn to Java.

Any suggestions, code snippets?

Thanks
-jeff otn
 
J

James McGill

I know the file is in little-endian format

If it's an image file and that's all you know about it, you could be in
a lot of trouble.

Maybe JAI can recognize your format and convert it magically. If the
byteorder is the problem you can plug your own recognizer and/or codec
into JAI. JAI's readers do support little-endian directly (many special
read data methods). http://java.sun.com/products/java-media/jai/
 
R

Rhino

Hi,

I have access to a binary file that contains 1 or more images. I am
trying to access the images in java so that I can extract them and
place them in a directory. I know the file is in little-endian format
and I used com.mindprod.ledatastream.LEDataInputStream to read it. I
the first line is ascii and tells me the length of the blob, but I am
unable to extract it and parse out the images.
I am a green horn to Java.

Any suggestions, code snippets?
Mindprod is owned by Roedy Green, a frequent contributor to this newsgroup.
If you give him a minute, he'll probably be along to answer you himself. :)

In the meantime, you may find useful information at his website that helps
you use this class for your intended purpose. Or not; I don't really know
since I haven't checked his site to see what he says about this class.
 
J

jeffotn

I know that the header file tells me the size of the blob is 35904 and
I have already read the first line. I have been told by the author of
the binary file that all I have to figure out in java is a way to read
the pointer that tell me x image is coming up and its this many out of
the entire 35904 bytes. Once I collect them, all I have to do is
output it with a .jpeg extension. I just do not think its that system.
He has sent me some C code, but I am new to Java and I do not know C
so I am constantly search for comparable methods and objects in Java to
do what the C code is doing. It looks like it reads the file, gets
some additional image header data and then extracts them 1 at a time

vPdExtractSingleImage(
CS_FILE fhInFile,
ULONGWORD ulLength,
UCHAR *sOutFile
){
UCHAR sBuffer[ 4096 ];
RETCODE rCode;
ULONGWORD ulWriteBytes = 0;
ULONGWORD ulReadBytes = 0;
ULONGWORD ulRemainBytes = ulLength;
size_t stCount;
CS_FILE fhOutFile;
/*
* Return if there is zero length
*/
if ( ulLength == 0 ){
CS_LPRINTF("No image data found for %s", sOutFile );
return;
}
fhOutFile = CsIoOpen(sOutFile, Write, CSIO_FILE );
if ( fhOutFile ){
do {
if ( ulRemainBytes < sizeof( sBuffer ) ){
ulReadBytes = ulRemainBytes;
}
else {
ulReadBytes = sizeof( sBuffer );
}
rCode = rCsIoRead( &sBuffer, sizeof(UCHAR),
ulReadBytes, &stCount, fhInFile);
if ( !CS_SUCCESS( rCode ) ) {
LOGRCODE( "rCsIoRead() failed", rCode );
}
rCode = rCsIoWrite( &sBuffer, sizeof( UCHAR ),
ulReadBytes, &stCount, fhOutFile );
if ( !CS_SUCCESS( rCode ) ) {
LOGRCODE( "rCsIoWrite() failed.", rCode );
}
ulWriteBytes += ulReadBytes;
ulRemainBytes -= ulReadBytes;
} while( CS_SUCCESS( rCode ) && ulWriteBytes < ulLength );
rCsIoClose(fhOutFile);
CS_LPRINTF("Image data(%lu) extracted into %s", ulWriteBytes,
sOutFile );
}
else {
CS_LPRINTF("Unable to open output file:%s", sOutFile );
}
}
 
N

Nigel Wade

I know that the header file tells me the size of the blob is 35904 and
I have already read the first line. I have been told by the author of
the binary file that all I have to figure out in java is a way to read
the pointer that tell me x image is coming up and its this many out of
the entire 35904 bytes. Once I collect them, all I have to do is
output it with a .jpeg extension. I just do not think its that system.
He has sent me some C code, but I am new to Java and I do not know C
so I am constantly search for comparable methods and objects in Java to
do what the C code is doing. It looks like it reads the file, gets
some additional image header data and then extracts them 1 at a time
[snipped C code]

The C code doesn't help at all. We don't know what the functions CsIoOpen,
rCsIoRead or rCsIoWrite do (and I don't particularly want to know).

Instead of using C code which you don't understand, you need to get the author
to send you a proper definition of the format of the data file.
 
C

Chris Uppal

Nigel said:
Instead of using C code which you don't understand, you need to get the
author to send you a proper definition of the format of the data file.

That's to say: a definition of the format in terms of the /bytes/ that make it
up.

-- chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top