Help with writing to a BufferedImage
I have a method which will create a buffered image with a diagonal line
across. For some reason I can not specify the color of this line (nor
the background) but I will end up with a black and white image.
--- cut ---
public Image buildDiagonalImage(Rectangle2D rect)
{
int width = (int)rect.getWidth();
int height = (int)rect.getHeight();
// Create buffered image that does not support transparency
BufferedImage bimage = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gs.getDefaultConfiguration();
// Create an image that does not support transparency
bimage = gc.createCompatibleImage(width, height, Transparency.OPAQUE);
bimage.getGraphics().setColor(Color.BLUE); // <-- Has no effect
bimage.getGraphics().drawLine(0,0,width, height);
return bimage;
}
--- cut ---
Can anyone spot what I am doing wrong? It would be much appreciated.
Casper