简体   繁体   English

Java:Canvas.drawline,如何画一条粗线

[英]Java: Canvas.drawline, how to draw a thicker line

Im trying to draw a lightning bolt on my canvas but the line is only one pixel wide.我试图在我的画布上画一道闪电,但这条线只有一个像素宽。 How can I make the line thicker?怎样才能让线条变粗?

 canvas.drawLine(lightningBoltArray[i].startXArray[k],lightningBoltArray[i].startYArray[k],lightningBoltArray[i].endXArray[k],lightningBoltArray[i].endYArray[k],paintHalfAlpha);

Is the trick somewhere in the settings of the applied paint?技巧是在应用油漆的设置中的某个地方吗?

If you're not doing something that allows you do to this you're probably painting incorrectly.如果你没有做一些允许你这样做的事情,那么你可能画错了。 Assuming that this is in a JPanel instance.假设这是在JPanel实例中。 It will also work for paint(Graphics g) in Canvas but most painting in Java is done using Swing它也适用于Canvas paint(Graphics g) ,但 Java 中的大多数绘画是使用Swing完成的

public void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2d = (Graphics2D) g;
   // other stuff
   float width = 3f;
   BasicStroke stroke = new BasicStroke(width);
   g2d.setStroke(stroke);
   g2d.drawLine(...);
   // more stuff
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM