【问题标题】:Java - drawing a scaled up shape with line thickness of 1Java - 绘制线条粗细为 1 的放大形状
【发布时间】:2012-08-01 02:52:37
【问题描述】:

当您使用Graphics2D.scale(); 绘制形状时,轮廓粗细也会被缩放。

有没有办法在不缩放线条粗细的情况下绘制它?除了使用上述函数之外,也许还有另一种有效的方法来扩展它?

【问题讨论】:

    标签: java scale draw shape graphics2d


    【解决方案1】:

    This question is similar。看来您必须弄乱 Stroke 对象才能设置正确的线宽。

    【讨论】:

      【解决方案2】:

      您必须将绘图保存为线向量列表,并以各种尺寸缩放和渲染绘图以保持所需的线条粗细。

      【讨论】:

        【解决方案3】:

        我刚刚找到了解决我自己问题的方法。我不知道它的效率如何,但它按预期工作:

        Area area = new Area(myShape); //myShape is the shape I want to scale
        AffineTransform at = new AffineTransform();
        at.scale(2,2);
        area = area.createTransformedArea(at);
        graphics2d.draw(area); //graphics2d is the Graphics2D instance to do the drawing
        

        也许有人可以告诉我这是否是一个好方法?

        【讨论】:

          猜你喜欢
          • 2015-12-12
          • 1970-01-01
          • 2012-12-04
          • 1970-01-01
          • 2013-05-03
          • 1970-01-01
          • 2018-10-13
          • 1970-01-01
          • 2014-09-03
          相关资源
          最近更新 更多