| | |
turning an image to binary code
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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?
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
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.
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)
private int[] capture() throws InterruptedException { dim = Toolkit.getDefaultToolkit().getScreenSize(); Image tmp = robot.createScreenCapture(new Rectangle(dim.width,dim.height)).getScaledInstance(800,600,BufferedImage.SCALE_SMOOTH); int pix[] = new int[IMG_WIDTH*IMG_HEIGHT]; PixelGrabber pg = new PixelGrabber(tmp,0,0,IMG_WIDTH,IMG_HEIGHT,pix,0,IMG_WIDTH); pg.grabPixels(); return pix; }
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 8
Hi everyone,
Save the image as an java object using streams.
Richard West
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
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
![]() |
Similar Threads
- adding an image to a java code (Java)
- Binary Code (C++)
- Using binary operators! (C)
- Converting binary code to decimal value. (C++)
- i need code for binary to decimal (it should be written in 'C') (C)
Other Threads in the Java Forum
- Previous Thread: Number formatting/Help with doubles
- Next Thread: How can i call my FileOutput method to output the array ?? really confused...
| Thread Tools | Search this Thread |
android api applet application array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) chat class classes client code columns component constructor database designadrawingapplicationusingjavajslider draw eclipse editor error errors event eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia link linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms smsspam sort sortedmaps sql string subclass support swing threads time tree unlimited utility webservices windows






