2014-02-24 131 views
0

我尝试画在整个图像的多个斜线(让他们之间有一个空格)绘制多个对角线我用这个代码来绘制水平线和垂直线:爪哇 - 对一个BufferedImage

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条对角线),希望您能帮助我。

谢谢。

回答

0

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

假设:

int spacing = 2; 

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

    gr.draw(dLines); 
} 
+0

这是输出:[链接](http://imageshack.com/a/img593/2373/xu0f.png) 但我需要像这样:[链接](http://imageshack.com/a/img38/8007/rhf.bmp) 在哪里我可以决定我需要多少行 –

0
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