0

How can I add text with outline to image using java.awt.* ?

Example below:

example

Lunigorn
  • 1,340
  • 3
  • 19
  • 27
  • 1
    Go to http://www.oracle.com/technetwork/java/javase/downloads/ and download the "Demos and Samples" package (either JDK 7 or 8 is fine). The Java2Demo sample program (a.k.a. "Java2D Demo") demonstrates what you want to do, and many other things, and includes all source code. – VGR Jul 25 '14 at 17:39
  • Are *you* writing the text on the image (or at least the code that writes it)? – Andrew Thompson Jul 26 '14 at 11:37

1 Answers1

0

I can guide you but You should know the basic functionality how awt work.
look at Smoothing a Smoothing a jagged. The algorithm to obtain the (crude) outline was relatively quick in the final versions. Creating a GeneralPath is astonishingly faster than appending Area objects.For better understanding refer this

The important part is this method:

public Area getOutline(Color target, BufferedImage bi) {
    // construct the GeneralPath
    GeneralPath gp = new GeneralPath();

    boolean cont = false;
    int targetRGB = target.getRGB();
    for (int xx=0; xx<bi.getWidth(); xx++) {
        for (int yy=0; yy<bi.getHeight(); yy++) {
            if (bi.getRGB(xx,yy)==targetRGB) {
                if (cont) {
                    gp.lineTo(xx,yy);
                    gp.lineTo(xx,yy+1);
                    gp.lineTo(xx+1,yy+1);
                    gp.lineTo(xx+1,yy);
                    gp.lineTo(xx,yy);
                } else {
                    gp.moveTo(xx,yy);
                }
                cont = true;
            } else {
                cont = false;
            }
        }
        cont = false;
    }
    gp.closePath();

    // construct the Area from the GP & return it
    return new Area(gp);
}
Community
  • 1
  • 1
Deepanshu J bedi
  • 1,530
  • 1
  • 11
  • 23