java - How to change the Color of the text on image using BufferedImage? -
using bufferedimage bgimage want set black color text on image.
bufferedimage bgimage = createbgimagefortext(); bgimage.creategraphics().drawstring(player.getplayername(), 25, 15); if ("y".equalsignorecase(player.getcaptain())) { bgimage.creategraphics().setpaint(color.black); } else { bgimage.creategraphics().setpaint(color.white); } mainimg.getgraphics().drawimage(bgimage, 10, 10, null); but text white default. how change color of text?
you need store graphics instance create bgimage.creategraphics() , can set color before drawing text:
bufferedimage bgimage = createbgimagefortext(); graphics2d g = bgimage.creategraphics(); if ("y".equalsignorecase(player.getcaptain())) { g.setpaint(color.black); } else { g.setpaint(color.white); } g.drawstring(player.getplayername(), 25, 15); g.dispose();
Comments
Post a Comment