我对另一个问题也有类似的答案,即使用多边形作为 AWT 剪辑。也许这在 J2ME 中受支持?您需要知道要排除的矩形的边界以及绘图区域的外部边界。
+-------------------+
| 剪辑绘图区|
+---+-----------+ |
| | 排除 | |
| | 面积 | |
| +-----------+ |
| |
+-------------------+
从 OP 编辑。
这个答案对我有用,并且 J2ME 支持 API。另一个问题的答案似乎有一个错误 - 坐标集需要从左外角和内顶部的点开始,以创建封闭的多边形。我的最终代码如下:
为了创建一个剪切形状,我使用了这个方法:
static public Shape getOutsideEdge(Graphics gc, Rectangle bb, int top, int lft, int btm, int rgt) {
int ot=bb.y , it=(ot+top);
int ol=bb.x , il=(ol+lft);
int ob=(bb.y+bb.height), ib=(ob-btm);
int or=(bb.x+bb.width ), ir=(or-rgt);
return new Polygon(
new int[]{ ol, ol, or, or, ol, ol, il, ir, ir, il, il },
new int[]{ it, ot, ot, ob, ob, it, it, it, ib, ib, it },
11
);
}
我将其设置到 Graphics 上下文中,然后填充我的矩形:
Rectangle tmp=new Rectangle(px,py,pw,ph);
gc.setClip(getOutsideEdge(gc,tmp,thickness,thickness,thickness,thickness));
gc.fillRoundRect(px,py,pw,ph,RADIUS,RADIUS);
然后我通过在每个角上画一个点来创造圆角内角的错觉:
gc.setClip(px,py,pw,ph);
gc.drawLine((px +thickness ),(py +thickness ),(px +thickness ),(py +thickness ));
gc.drawLine((px+pw-thickness-1),(py +thickness ),(px+pw-thickness-1),(py +thickness ));
gc.drawLine((px +thickness ),(py+ph-thickness-1),(px +thickness ),(py+ph-thickness-1));
gc.drawLine((px+pw-thickness-1),(py+ph-thickness-1),(px+pw-thickness-1),(py+ph-thickness-1));