【问题标题】:java - Drawing multiple diagonal lines on a BufferedImagejava - 在 BufferedImage 上绘制多条对角线
【发布时间】:2014-02-24 18:05:25
【问题描述】:

我试图在整个图像上绘制多条对角线(在它们之间留一个空间)我使用此代码来绘制水平和垂直线:

for (int z = 1; z < partToCrop; z++) {
    Shape hLines = new Line2D.Float(0, cropInPartWidth*z, chunkWidth, cropInPartWidth*z);
    Shape vLines = new Line2D.Float(cropInPartHeight*z, 0, cropInPartHeight*z, chunkHeight);
    gr.draw(hLines); //gr is a BufferedImage
    gr.draw(vLines);
}

在哪里

int partToCrop = 5;
float cropInPartWidth = imgWidth / partToCrop; 
float cropInPartHeight = imgHeight / partToCrop;

而且效果很好。现在我需要在整个图像上绘制多条倾斜度为 45° 和 -45° 的对角线(即 4 条对角线),希望你能帮助我。

谢谢。

【问题讨论】:

    标签: java image draw


    【解决方案1】:
    Shape firstLine = new Line2D.Float(0, imgHeight, imgWidth, 0); // this line is from bottom left to top right
    Shape secondLine = new Line2D.Float(0, 0, imgWidth, imgHeight); // this line is from top left to bot right
    

    【讨论】:

      【解决方案2】:

      实际上这对我来说似乎更容易。

      假设imgDim = imgHeight = imgWidth

      int spacing = 2;
      
      for (int z = 1; z < imgDim; z = z + spacing) 
      {
          Shape dLines = new Line2D.Float(0, z, z, 0); 
      
          gr.draw(dLines); 
      }
      

      【讨论】:

      • 这是输出:link 但我需要这样的东西:link 我可以决定我需要多少行
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-12
      • 2013-08-06
      • 2013-03-13
      • 2016-06-15
      • 1970-01-01
      • 2015-10-02
      相关资源
      最近更新 更多