Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

Extracting image from binary file

Thread view: 
jeffotn@gmail.com - 16 Feb 2006 00:40 GMT
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
James McGill - 16 Feb 2006 02:08 GMT
> 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/ 
jeffotn@gmail.com - 16 Feb 2006 17:20 GMT
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 );
   }
}
Nigel Wade - 17 Feb 2006 12:12 GMT
> 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
[quoted text clipped - 6 lines]
> 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.

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

Chris Uppal - 17 Feb 2006 12:58 GMT
> 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
Rhino - 16 Feb 2006 04:52 GMT
> Hi,
>
[quoted text clipped - 7 lines]
>
> 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.

--
Rhino
Roedy Green - 17 Feb 2006 06:10 GMT
On Wed, 15 Feb 2006 23:52:45 -0500, "Rhino"
<no.offline.contact.please@nospam.com> wrote, quoted or indirectly
quoted someone who said :

>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. :-)
I answered this elsewhere.  Don't multipost. It fragments the
discussion.
. see http://mindprod.com/jgloss/multipost.html

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.