2

I have a weird problem - I'm trying to write a text string over a transparent GIF picture. I'm using awt Graphics2D object, and for some reason, I cannot affect the way the text looks - its color, its alignment and so on. Every time I use drawString with a string, it is white and centered left. Is this a problem with my jre? With GIF format? Or the fact that the picture is transparent?

I tried doing this: (TextAttributes is just some container class I created)

Map<TextAttribute, Object> fontAtts = new Hashtable<TextAttribute, Object>();

fontAtts.put(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
fontAtts.put(TextAttribute.FAMILY, TextAttributes.type);
fontAtts.put(TextAttribute.FOREGROUND, TextAttributes.color);
fontAtts.put(TextAttribute.SIZE, TextAttributes.size);

Font font = new Font(fontAtts);
BufferedImage image = getImage(picturePath, pictureName, format);\\just gives me the buffered image
Graphics2D g2 = image.createGraphics();

//first way:    
g2.setFont(font);
g2.drawString("bla blah", 200,150)

//second way
g2.setPaint(TextAttributes.color);
g2.drawString("bla blah", 200,150)

//third way
g2.setColor(Color.RED);
g2.drawString("bla blah", 200,150)

//fourth way
AttributedString x = new AttributedString("blah blah", fontAtts);
g2.drawString(x.getIterator(),200,150)

but nothing works :(

kleopatra
  • 51,061
  • 28
  • 99
  • 211

0 Answers0