This section illustrates you how to generate image files. For this, we have used the class ImageIO which provides methods for locating ImageReaders and ImageWriters.
The method createGraphics() creates a Graphics2D and draw into the BufferedImage. To render the specified font on a particular screen, the class FontMetrics is used. The method getFontMetrics() get the font metrics of current font. The method getAscent() provides the font ascent of the font. The method stringWidth(text) returns the total width to show the specified string in the specified font.
The method writes() writes an image using ImageWriter in the file.
Here is the code of GenerateImageType.java
After compilation, when you the run the program, the image files are saved in the specified location. The image file contains the following image:
Liked it! Share this Tutorial