Creating a text with transparent background using javax.media.j3d.Raster
Hi, I'm trying to display a text in Java3D using the Raster but I'm not sure to make the background of the text transparent. Does anyone have any ideas.
Here's my code for creating the Raster image:
private javax.media.j3d.Raster getRaster(String str, boolean rotate) {
// Create an empty raster.
javax.media.j3d.Raster raster = new javax.media.j3d.Raster();
// Get a font metrics.
Font font = new Font("Times", Font.PLAIN, 12);
FontMetrics fm = getFontMetrics(font);
// Calculate the raster size.
int width = SwingUtilities.computeStringWidth(fm, str) + 6;
int height = 18;
// Create an BufferedImage.
BufferedImage image = new BufferedImage(width,
height,
BufferedImage.TYPE_INT_BGR);
// Draw the input string on the BufferedImage.
Graphics2D g2d = (Graphics2D) image.getGraphics();
g2d.setFont(font);
g2d.setColor(Color.WHITE);
g2d.drawString(str, 3, 14);
// Set the BufferedImage to the raster.
raster.setImage(new ImageComponent2D(ImageComponent2D.FORMAT_RGB, image));
raster.setSize(width, height);
raster.setType(javax.media.j3d.Raster.RASTER_COLOR);
raster.setCapability(javax.media.j3d.Raster.ALLOW_IMAGE_WRITE);
raster.setCapability(javax.media.j3d.Raster.ALLOW_SIZE_READ);
return raster;
}
Thank you for your help.