Display text in an image in Java

Are there any beautiful libraries for rendering text in an image for Java?

Java has a 2d text library, http://java.sun.com/docs/books/tutorial/2d/text/index.html , but not sure if it's better to use a library.

+4
source share
2 answers

It depends on what you want to do. Java2D is a fairly rich text environment, as seen on the " Fonts" tab in the demo located in the folder demo/jfc/Java2Din the demos and examples ; The source code for the demonstration of fonts can be found in the attached src.zip. Based on this foundation, I have achieved good results using text-based utilities in , now part . When you annotate the image here shows a basic example and you may want to learn how to use , as previewed in demo version Java2D . JCommon JFreeChart 1.5 AlphaComposite

image

+4
source

Here's a way to draw text on an image:

public void displayText(BufferedImage image, String text, Font font, int x, int y){
   Graphics2d g = image.createGraphics();
   g.setFont(font);
   g.drawString(text, x, y);
   g.dispose();
}
+9

Source: https://habr.com/ru/post/1740558/


All Articles