如何使用java.awt.*添加文本大纲?
如何使用java.awt.*将带有大纲的文本添加到图像中 示例如下:如何使用java.awt.*添加文本大纲?,java,image,image-processing,text,awt,Java,Image,Image Processing,Text,Awt,如何使用java.awt.*将带有大纲的文本添加到图像中 示例如下: 我可以指导您,但您应该知道awt的基本功能。 看一张平滑的照片。在最终版本中,获得(粗略)轮廓的算法相对较快。创建GeneralPath比附加Area对象快得惊人 重要的部分是这种方法: public Area getOutline(Color target, BufferedImage bi) { // construct the GeneralPath GeneralPath gp = new Genera
我可以指导您,但您应该知道
awt
的基本功能。看一张平滑的照片。在最终版本中,获得(粗略)轮廓的算法相对较快。创建
GeneralPath
比附加Area
对象快得惊人
重要的部分是这种方法:
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);
}
公共区域getOutline(颜色目标,缓冲图像bi){
//构造通用路径
GeneralPath gp=新的GeneralPath();
布尔控制=假;
int targetRGB=target.getRGB();
对于(int xx=0;xx)转到并下载“Demos and Samples”包(JDK 7或8都可以)。Java2Demo示例程序(也称为“Java2D Demo”)演示了您要做的事情和许多其他事情,并包括所有源代码。您是否在图像上编写文本(或至少是编写它的代码)?