Since the Brazilian government does not have a public API for postal codes, I am trying to reverse engineer the code that correios.com.br uses to generate the image below so that I can create my own images for training the OCR program.

I believe that I already have almost everything except text and colors:

I'm not interested in colors right now, but the text interval really bothers me. For example, look at "Ti" in "Tijuca". These two letters are very close to each other in the original image, and I can not reproduce this function. I already tried to get the font by setting the values to TextAttribute.TRACKING and TextAttribute.KERNING , but that didn't work.
My code follows:
import java.awt.Color; import java.awt.font.TextAttribute; import java.awt.Font; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.Hashtable; import javax.imageio.ImageIO; public class CreateImage { public static void main(String[] args) { int width = 570; int height = 120; boolean new_image = true; BufferedImage img; if (!new_image) { try { img = ImageIO.read(new File("original.jpg")); } catch (IOException e) { e.printStackTrace(); new_image = true; img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); } } else { img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); } Graphics2D g2d = img.createGraphics(); if (new_image) {
My question is: what are the other options for controlling how the line is spaced when it is drawn? Do you have ideas on what source code can do?
Thanks!
java fonts image awt
jbochi
source share