How can I add text with outline to image using java.awt.* ?
Example below:
How can I add text with outline to image using java.awt.* ?
Example below:
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);
}