我试图在整个图像上画多条对角线(在它们之间留一个空格)我用这段代码绘制水平和垂直线:
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;
并且运作良好。现在我需要绘制多条对角线(即4条对角线),整个图像的倾斜度为45°和-45°,希望你能帮助我。
感谢。
答案 0 :(得分:0)
实际上这对我来说似乎更容易。
假设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);
}
答案 1 :(得分: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