Java如何绘制和填充有孔的多边形 [英] Java how to draw and fill a Polygon which has holes

查看:471
本文介绍了Java如何绘制和填充有孔的多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试绘制和填充在Java中有孔的多边形.通常,这不会有什么大问题,因为我先绘制外圈,然后再用背景色绘制内圈.

I am currently trying to draw and fill a Polygon which has a hole in it in Java. Normally this would not be a big problem, since I would draw the exterior ring and then draw the interior ring with the color of the background.

但是问题是,多边形显示在应该通过孔看到"的图像上方.

But the problem is, that the polygon is displayed above a image which should be "seen" through the hole.

我正在用Java编写代码,并将 JTS拓扑套件用于我的几何数据.

I am writing the code in Java and am using JTS Topology Suite for my geometry data.

这是我当前的代码,该代码只绘制边框并用颜色填充多边形.

This is my current code, which just paints the border and fills the polygon with a color.

private void drawPolygon(com.vividsolutions.jts.geom.Polygon gpoly, Color color, Graphics2D g2d){

    java.awt.Polygon poly = (java.awt.Polygon)gpoly;

    for(Coordinate co : gpoly.getExteriorRing().getCoordinates() {
        poly.addPoint(co.x, co.y);
    }
    g2d.setColor(col);
    g2d.fill(poly);

    g2d.setColor(Color.BLACK);
    g2d.draw(poly);
}

可悲地 java.awt.Polygon 不支持带孔多边形.

Sadly java.awt.Polygon does not support Polygons with holes.

推荐答案

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆