Can someone check my syntax here? I am passing "Times New Roman","Arial","Verdana" to fontName
and using 8,12,15 etc. for fontSize
. It never changes the font here. I am doing this to write some text over an image.
Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics();
g2d.drawImage(photo, 0, 0, null);
g2d.setColor(Color.white);
Font font = new Font(fontName, Font.PLAIN, fontSize);
g2d.setFont(font);
g2d.drawString(text,x,y);
I finally found out that none of fonts from my list were there on the system so I had to use getAllFonts() method and pass only those fonts from the list .