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 / First Aid / February 2006

Tip: Looking for answers? Try searching our database.

Extracting image from binary file

Thread view: 
jeffotn@gmail.com - 16 Feb 2006 00:45 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
Rhino - 16 Feb 2006 05:45 GMT
> Hi,
>
[quoted text clipped - 10 lines]
> Thanks
> -jeff otn

Please don't multipost the same question on different Java newsgroups. You
just waste the time of people who don't know you have already received
answers on the other newsgroups.

Give the original newsgroup time to answer your question before giving up
and trying another one. Depending on how active the newsgroup is, an answer
can take hours, even a couple of days to arrive and a useful answer may take
even longer.

--
Rhino
Stefan Schulz - 16 Feb 2006 10:04 GMT
While i am not familiar with the LEDataInputStream (which is not a
standard class), i would suggest you ditch the "leading info"
altogether. The ImageIO class is able to figure that out all by itself.

One you have a "clean" imagefile, this is the general way to go about
things:

File imageFile = new File("/path/to/your/image");
BufferedImage myImage = ImageIO.read(imageFile);
doSomethingWith(myImage);
Roedy Green - 16 Feb 2006 14:51 GMT
On 16 Feb 2006 02:04:17 -0800, "Stefan Schulz"
<schulz.stefan@gmail.com> wrote, quoted or indirectly quoted someone
who said :

>While i am not familiar with the LEDataInputStream (which is not a
>standard class), i would suggest you ditch the "leading info"
>altogether. The ImageIO class is able to figure that out all by itself.

It behaves just like DataInputStream except is expects binary fields
to be little-endian.

see http://mindprod.com/products1.html#LEDATASTREAM

You might like to look at my code that gets the image size out of an
image or Marco Schmidt's that gets even more.

See http://mindprod.com/jgloss/imageinfo.html

Signature

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

Roedy Green - 16 Feb 2006 14:25 GMT
>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
[quoted text clipped - 3 lines]
>unable to extract it and parse out the images.
>I am a green horn to Java.

you could read that first piece with LEDataInputStream as  byte byte
byte, then convert it to char[] then String.

See http://mindprod.com/conversion.html
Signature

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

jeffotn@gmail.com - 17 Feb 2006 19:27 GMT
Roedy,

Thanks for the conversion link, I already converted the first ascii
line and converted the the hex data to appropriate type.  Next issue is
reading the next set of bytes that constitute the image header
information(with pointers to image start, and image length then repeats
until eof.  I am trying to map data types from a C construct and some I
can not find online I have the Java type with a ? since i am unsure

C type
      Java type
-------------------------------------------------------------------------------------------------------------------
UCHAR elementname[24]     PACKED                          char[24]
UWORD elementname[4]      PACKED                          int[4]
ULONGWORD elementname PACKED                          String/long ?
DWORD elementname          PACKED                          long/String
?

Also, should I be trying to read this file as a sequential buffered
little-endian file or unbuffered?

Thanks
Roedy Green - 18 Feb 2006 00:15 GMT
>UCHAR elementname[24]     PACKED                          char[24]
>UWORD elementname[4]      PACKED                          int[4]
[quoted text clipped - 4 lines]
>Also, should I be trying to read this file as a sequential buffered
>little-endian file or unbuffered?

urchar is unsigned byte in C-speak is it not.
See http://mindprod.com/jgloss/unsigned

The C people are quite casual about having standard meanings for their
types. If you can find the source and its libraries, chase the
definition chains back to figure out if  words are 16 or 32 bits long
and if chars are 8 or 16 bits long.  Or study some sample files with
known data contents.

You can peek with a hex viewer to discover the byte sex/endianness and
other fine points of the layout definition.
See http://mindprod.com/jgloss/hex.html
http://mindprod.com/jgloss/endian.html

Then, once you understand the format, you can easily read everything
with either DataInputStream or LEDataInputStream.
See http://mindprod.com/products1.html#LEDATASTREAM
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



©2008 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.