• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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

Please suggest me..




--
With Regards,
M. Bharathi
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Images are binary. What exactly are you trying to do? What should the result of the conversion be?
 
muthu bharathi
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
muthu bharathi
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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]
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Indeed. Maybe muthu will clue us in what we're looking at.
reply
    Bookmark Topic Watch Topic
  • New Topic