turning an image to binary code

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2005
Posts: 192
Reputation: stupidenator is an unknown quantity at this point 
Solved Threads: 4
stupidenator's Avatar
stupidenator stupidenator is offline Offline
Junior Poster

turning an image to binary code

 
0
  #1
Apr 2nd, 2005
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?
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: turning an image to binary code

 
0
  #2
Apr 2nd, 2005
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.

  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. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 8
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Re: turning an image to binary code

 
0
  #3
Apr 2nd, 2005
Hi everyone,

Save the image as an java object using streams.

Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond

Tell me what type of software do you like and what would you pay for it

http://www.daniweb.com/techtalkforums/thread19660.html
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 192
Reputation: stupidenator is an unknown quantity at this point 
Solved Threads: 4
stupidenator's Avatar
stupidenator stupidenator is offline Offline
Junior Poster

Re: turning an image to binary code

 
0
  #4
Apr 3rd, 2005
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...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC