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?
Image i = Toolkit.getDefaultToolkit( ).createIm age("your. bmp");
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?
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)
{
}
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)
{
}
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( ).createIm age()
Like CEHJ Said:
Image i = Toolkit.getDefaultToolkit( ).createIm age("your. bmp");
:-)
Image i = Toolkit.getDefaultToolkit(
:-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That's exactly what I wanted!