Link to home
Start Free TrialLog in
Avatar of jc31415
jc31415

asked on

Bit Map Image

I have a file which contains the bit map for an image. Is there a facility in Java to display that image i.e. setting the pixels based on that bit map?
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Image i = Toolkit.getDefaultToolkit().createImage("your.bmp");
Avatar of jc31415
jc31415

ASKER

My image is not a "BMP" image. It just a series of 1's and 0's that represent the value of each pixel.
How are these 1s and 0s stored?
Avatar of jc31415

ASKER

That shouldn't matter. I just want to read them and set the apporpriat pixel. I have often done this in C++, where there is a function SetPixel.
It does matter, because different files are interpreted in different ways. What have you got - a 'binary' file?
You need to look at BufferedImage (JDK > 1.3) or MemoryImageSource (JDK > 1.0 )

have a look here for an example:

    int iw = im.getWidth( parent ) ;
    int ih = im.getHeight( parent ) ;

    int[] imagearr = new int[ iw * ih ] ;

    PixelGrabber pg = new PixelGrabber( im, 0, 0, iw, ih, imagearr, 0, iw );
    try
    {
      pg.grabPixels();
    }
    catch (InterruptedException e)
    {
    }
Avatar of jc31415

ASKER

That's what I wanted, except for one thing. It is for an applet, and everything I found on a web search was for an applet. Can't an image be created for a program? If not I'll just have to use the applet version.
Toolkit.getDefaultToolkit().createImage()
Like CEHJ Said:

Image i = Toolkit.getDefaultToolkit().createImage("your.bmp");

:-)
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jc31415

ASKER

That's exactly what I wanted!