在用 java 2d 进行画图时可以非常方便的设置线条的粗细及接头的形状。下面是一个简单的例子供大家参考:
float thick = 0.5f; //设置画刷的粗细为 0.5
bufferedimage bi = new bufferedimage(800, 600, bufferedimage.type_int_rgb);
graphics2d g = (graphics2d)bi.getgraphics();
stroke stroke = g.getstroke(); //得到当前的画刷
g.setstroke(new basicstroke(thick, basicstroke.cap_square, basicstroke.join_round)); //设置新的画刷
g.draw(new line2d.float(x1, y1, x2, y2)); 画线
g.setstroke( stroke ); //将画刷复原
闽公网安备 35060202000074号