I have an icon that I want to write to an ouput file. The icon is a circle - specifically, it is JOptionPane.errorIcon. So I turn it into a BufferedImage like this:
int w = icon.getIconWidth();
int h = icon.getIconHeight();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
BufferedImage buffImage = gc.createCompatibleImage(w, h);
//Now I have to paint it
Graphics2D g = buffImage.createGraphics();
icon.paintIcon(null, g, 0, 0);
g.dispose();
//Now write to file
File file = new File("C:\\location");
try{
ImageIO.write(buffImage, "bmp", file);
}catch(Exception e){
e.printStackTrace();}
The problem is that I turned my icon into a rectangle, and now it has a black background around the circle (this is bad). I either just want the circle, or I want to paint the background grey instead of black, how can I do this?
I have tried a couple different things such as setBackground(color) but that doesn't seem to work.
How to set the background color of an output image file
Started by cliveceps, Jun 09 2010 11:45 AM
1 reply to this topic


Sign In
Create Account

Back to top









