BufferedImages didn’t exist for 1.1. You could muck around with the ColorModels for the regular images, but that would be something of a PITA. A much better idea might be to create your own ImageProducer. e.g.:
import java.awt.*;
import java.awt.image.*;
public class GlyphBlitter implements ImageProducer
{
private ColorModel model = new DirectColorModel(32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0);
private ImageConsumer consumer;
private Image image;
private int width;
private int height;
private int[][] pixels;
public GlyphBlitter(int width, int height)
{
this.width = width;
this.height = height;
//Creates space for the lower 128 characters of
//the ASCII set.
this.pixels = new int[128][width*height*4];
this.image = Toolkit.getDefaultToolkit().createImage(this);
}
//Make sure you only pass a character between 0
//and 127!!!
public void setGlyph(char c, int[] pixels)
{
this.pixels[(int)c] = pixels;
}
//Make sure you only pass a character between 0
//and 127!!!
public void render(Graphics g, char c)
{
if(consumer != null)
{
consumer.setPixels(0, 0, width, height, model, pixels[(int)c], 0, width);
consumer.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
}
g.drawImage(image, 0, 0, width, height, null);
}
public void addConsumer(ImageConsumer consumer)
{
this.consumer = consumer;
consumer.setDimensions(width, height);
consumer.setHints(ImageConsumer.TOPDOWNLEFTRIGHT |
ImageConsumer.COMPLETESCANLINES |
ImageConsumer.SINGLEPASS |
ImageConsumer.SINGLEFRAME);
consumer.setColorModel(model);
}
public boolean isConsumer(ImageConsumer imageConsumer)
{
//We'll take anyone
return true;
}
public void removeConsumer(ImageConsumer imageConsumer)
{
//nothing to do
}
public void requestTopDownLeftRightResend(ImageConsumer imageConsumer)
{
//ignore
}
public void startProduction(ImageConsumer imageConsumer)
{
addConsumer(imageConsumer);
}
//Recolors the character
public void setColor(char c, int color)
{
for(int i=0; i<pixels.length; i++)
{
if(pixels[(int)c][i] != 0x00000000)
{
pixels[(int)c][i] = color;
}
}
}
}
I haven’t actually tried compiling the above, but something like it should do the trick. All you need to do is create the object with the width and height of the characters (I’m assuming that you’re using fixed width), then loop through and set the pixels for each character you need to display. Once you have it loaded, you can render the character by calling “render(Graphics g, char c)” with the character you want to draw. To recolor the character, call “setColor(int color)”.
The only thing I’ve left up to you, is breaking up your images into individual pixel arrays for each character. I might even suggest packing the pixels directly into a file instead of breaking them up when your applet starts. A good example of pixel packing can be found in my Defender game (see: http://java.dnsalias.com/4k). Download the source code, and look in “src/tools/ImagePacker.java”. That program takes a set of graphic files and packs them into a 1 bit per pixel format. A viewer is also included for debugging.
If you have any questions, feel free to ask!