aspose file tools
The moose likes Java in General and the fly likes convert image(.jpg) in to binary format using java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Meteor in Action this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "convert image(.jpg) in to binary format using java" Watch "convert image(.jpg) in to binary format using java" New topic
Author

convert image(.jpg) in to binary format using java

muthu bharathi
Ranch Hand

Joined: Dec 10, 2008
Posts: 97
Hi,

How to convert image(.jpg or .bmp) in to binary format using java?

Please suggest me..




--
With Regards,
M. Bharathi
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42955
    
  73
Images are binary. What exactly are you trying to do? What should the result of the conversion be?
muthu bharathi
Ranch Hand

Joined: Dec 10, 2008
Posts: 97
ulf,

I have some .jpg images.

I give my input as <filename>.jpg, It should print the corresponding binary format of an image using java

The output should be the binary format for an image.

--
With Thanks and Regards,
M. Bharathi
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19642
    
  43

The output should be the binary format for an image.



As Ulf already mentioned, what does this mean? Meaning given a sample jpg file, how should this output look like?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
muthu bharathi
Ranch Hand

Joined: Dec 10, 2008
Posts: 97
Hi,

Now i've a xml. I've a tag named as <check_Image>, in this tag i've converted the image in to Readable format. I need to be convert in to the corresponding image. Here with i've included the xml file....

<EE_EAI_MESSAGE>
<Check_Image>
ffd8ffe000104a464</Check_Image>

</EE_EAI_MESSAGE>


-- with regards
M. Bharathi

[RP] removed most of the HEX string to preserve the layout [/RP]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19965
    
  25

Do you know how to read a file in bytes? You can then use Integer.toHexString to convert each byte to a two-character HEX string. Keep two things in mind though:
1) a byte is between -128 and 127, and you don't want to convert negative numbers to a HEX string. Add 256 to negative numbers first, thereby making the range 0 to 255 (0 and FF in HEX).
2) Integer.toHexString will return a one-character HEX string if the number is between 0 and 15 (0 and F in HEX). Don't forget to add that extra 0 before the HEX string.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42955
    
  73
Of course, you have to know the internal structure of that hex string. Is it RGB, RGBA, ARGB, CMY or something else? Do you know the width and height of the image?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19965
    
  25

Ulf Dittmer wrote:Of course, you have to know the internal structure of that hex string. Is it RGB, RGBA, ARGB, CMY or something else? Do you know the width and height of the image?

If the string is the HEX representation of the file itself then that doesn't matter. The code reading the XML file can simply turn it back into the original file.
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42955
    
  73
Indeed. Maybe muthu will clue us in what we're looking at.
 
jQuery in Action, 2nd edition
 
subject: convert image(.jpg) in to binary format using java