944,111 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 21668
  • Java RSS
Apr 2nd, 2005
0

turning an image to binary code

Expand Post »
Hey everyvody... I have this crazy idea for a program... I want to be able to load an image (most likely a .jpg) into a java program and then I want the program to print out the binary code that makes up the image and save it to a .txt file. I know how to do the i/o stuff... but I can't think of how to extract the binary code from the image.... Anybody know how to do this?
Similar Threads
Reputation Points: 18
Solved Threads: 4
Junior Poster
stupidenator is offline Offline
192 posts
since Mar 2005
Apr 2nd, 2005
0

Re: turning an image to binary code

I think you would have to create a PixelGrabber which returns an array of ints made from the image. Once you have that, I think you could use this method to convert the ints to binary:

Integer.toBinaryString(int);

Here is an example of a Pixel Grabber that creates a screen shot and throws it into an array of ints.

Java Syntax (Toggle Plain Text)
  1. private int[] capture() throws InterruptedException {
  2. dim = Toolkit.getDefaultToolkit().getScreenSize();
  3. Image tmp = robot.createScreenCapture(new Rectangle(dim.width,dim.height)).getScaledInstance(800,600,BufferedImage.SCALE_SMOOTH);
  4. int pix[] = new int[IMG_WIDTH*IMG_HEIGHT];
  5. PixelGrabber pg = new PixelGrabber(tmp,0,0,IMG_WIDTH,IMG_HEIGHT,pix,0,IMG_WIDTH);
  6. pg.grabPixels();
  7. return pix;
  8. }
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Apr 2nd, 2005
0

Re: turning an image to binary code

Hi everyone,

Save the image as an java object using streams.

Richard West
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004
Apr 3rd, 2005
0

Re: turning an image to binary code

Alright, the pixelgrabber worked perfectly! Thank you... But now is there a way i can compile the binary back to an image after i modify it a little bit? I'm trying to make something of a stegonagraphy program but I can't think of how to save it back to an image again...
Reputation Points: 18
Solved Threads: 4
Junior Poster
stupidenator is offline Offline
192 posts
since Mar 2005
Feb 4th, 2011
0
Re: turning an image to binary code
Generate an XML..use jDom...bingo
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Urchin1111 is offline Offline
1 posts
since Feb 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Class name cannot be resolved to a type
Next Thread in Java Forum Timeline: For looping and numbers





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC