aspose file tools*
The moose likes Applets and the fly likes gif image shows only in black and white Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "gif image shows only in black and white" Watch "gif image shows only in black and white" New topic
Author

gif image shows only in black and white

Rikhard Parssinen
Greenhorn

Joined: Mar 03, 2005
Posts: 1
Hello...

I'm trying to convert normal image to PlanarImage but the PlanarImage will show only black & white image in the applet. My guess is that it has something to do with bands but I can't figure out how to solve the problem.

Here is the code what I'm trying to use in applet's init method

public void init(){
Image my_gif;
URL base;
MediaTracker mt;

mt = new MediaTracker(this);
try {
base = getCodeBase();
}
catch (Exception e) {}

my_gif = getImage(base,"image.gif");

mt.addImage(my_gif,1);
try {
mt.waitForAll();
}
catch (InterruptedException e) {}

int imageHeight = my_gif.getHeight(this);
int imageWidth = my_gif.getWidth(this);

int numBands = 3;
int len = imageHeight * imageWidth * numBands;

byte[] imageData = null;

PixelGrabber pixeli = new PixelGrabber(my_gif, 0, 0, imageWidth, imageHeight,false);
SeekableStream ss = null;
try {
pixeli.grabPixels();
imageData = (byte[])pixeli.getPixels();
} catch (InterruptedException e2) {
e2.printStackTrace();
}

ColorModel cm = pixeli.getColorModel();
SampleModel sm = cm.createCompatibleSampleModel(imageWidth,imageHeight);

TiledImage tiledImage = new TiledImage(new Point(),sm,imageWidth,imageHeight);
DataBufferByte dbb = new DataBufferByte(imageData,len);

Raster raster = RasterFactory.createWritableRaster(sm,dbb,new Point());
tiledImage.setData(raster);

PlanarImage image = (PlanarImage)tiledImage;
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: gif image shows only in black and white
 
Similar Threads
Paint
Image Coordinates and Scaling
Picture Woes
How can I display an image on an AWT panel
Correct this code for event handling.