Java 怎么绘制虚线边界框

2019年8月20日22:29:12Java 怎么绘制虚线边界框已关闭评论 212 539字阅读1分47秒

1.简介

Java 怎么绘制虚线边界框?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */


import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;

public class Main {
    public static void drawDashedBoundingBox(Color c, Graphics g, int x1,
            int y1, int x2, int y2) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.setColor(c);
        final float dash[] = { 2.0f };
        final BasicStroke dashed = new BasicStroke(1.0f,
                BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash,
                0.0f);
        g2d.setStroke(dashed);
        g2d.draw(new Rectangle2D.Double(x1, y1, x2 - x1, y2 - y1));
    }
}

 
编程十万个怎么办