Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

gif image shows only in black and white

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic