3 Replies - 19878 Views - Last Post: 16 February 2011 - 09:07 AM Rate Topic: -----

#1 nasrul   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 08-February 11

How to convert an image into binary..?

Posted 16 February 2011 - 08:14 AM

hi,i'm done with reading an image from file but now i need help how to convert thew image that i read from the file into binary?anyone plz help me..here is my code..

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;

/**
 * This class demonstrates how to load an Image from an external file
 */
public class LoadImageApp extends Component {
          
    BufferedImage img;

    public void paint(Graphics g) {
        g.drawImage(img, 0, 0, null);
    }

    public LoadImageApp() {
       try {
           img = ImageIO.read(new File("strawberry.jpg"));
       } catch (IOException e) {
       }

    }

    public Dimension getPreferredSize() {
        if (img == null) {
             return new Dimension(100,100);
        } else {
           return new Dimension(img.getWidth(null), img.getHeight(null));
       }
    }

    public static void main(String[] args) {

        JFrame f = new JFrame("Load Image Sample");
            
        f.addWindowListener(new WindowAdapter(){
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
                }
            });

        f.add(new LoadImageApp());
        f.pack();
        f.setVisible(true);
    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: How to convert an image into binary..?

#2 japanir   User is offline

  • jaVanir
  • member icon

Reputation: 1014
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: How to convert an image into binary..?

Posted 16 February 2011 - 08:35 AM

Images are binary. what exactly do you mean?
Was This Post Helpful? 0
  • +
  • -

#3 nasrul   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 08-February 11

Re: How to convert an image into binary..?

Posted 16 February 2011 - 08:47 AM

View Postjapanir, on 16 February 2011 - 08:35 AM, said:

Images are binary. what exactly do you mean?


sorry.what i mean is i want to view this image in 01 format
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12742
  • View blog
  • Posts: 45,926
  • Joined: 27-December 08

Re: How to convert an image into binary..?

Posted 16 February 2011 - 09:07 AM

Each pixel has an RGB value, which is an int, that can be represented in binary format. A better question, though, is why you want to convert an image to binary? Really it's just easier to serialize the image.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1