gpt4 book ai didi

java - 如何恢复 BasicStroke 类中的默认笔画?

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:43:27 26 4
gpt4 key购买 nike

我有一个程序,我在其中定义了一堆新的破折号模式,并使用 BasicStroke 类使它们成为笔划。比我用的.setStroke() 方法并用我的破折号图案画线。现在我希望能够 setStroke() 回到默认的破折号模式(实线)。我该怎么做呢?这是我的代码:

    float[] dash1 = {2f, 0f, 2f};
float[] dash2 = {1f, 1f, 1f};
float[] dash3 = {16f, 10f, 4f, 10f};
float[] dash4 = {4f, 4f, 1f};

Graphics2D g2d = (Graphics2D) g.create();
g2d.drawLine(20, 40, 250, 40);

BasicStroke bs1 = new BasicStroke(1, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_ROUND, 1.0f, dash3, 0f);

BasicStroke bs2 =new BasicStroke(1, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_ROUND, 1.0f, dash3, 16f);

BasicStroke bs3 = new BasicStroke(1, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_ROUND, 1.0f, dash3, 2f);

BasicStroke bs4 = new BasicStroke(1, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_ROUND, 1.0f, dash4, 2f);



g2d.setStroke(bs1);
g2d.drawLine(20, 80, 250, 80);

g2d.setStroke(bs2);
g2d.drawLine(20, 120, 250, 120);

g2d.setStroke(bs3);
g2d.drawLine(20, 160, 250, 160);

g2d.setStroke(bs4);
g2d.drawLine(20, 200, 250, 200);

最佳答案

你可以把它存储在一个变量中,然后像@StanislavL 说的那样访问它

    Stroke defaultStroke;

Graphics2D g2d = (Graphics2D) g.create();

defaultStroke = g2d.getStroke();
//
//do your thing
//
//reset by
g2d.setStroke(defaultStroke);

关于java - 如何恢复 BasicStroke 类中的默认笔画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31061106/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com