多维数组如何在java中对角反射图像
我有以下代码,以便以对角线方式反映图像:
public void mirrorDiagonal() {
Pixel[][] pixels = this.getPixels2D();
Pixel topRightPixel = null;
Pixel bottomLeftPixel = null;
int maxLength;
if (pixels.length < pixels[0].length) { maxLength = pixels.length; }
else {maxLength = pixels[0].length; }
for (int row = 0; row < maxLength; row++)
{
for (int col = row; col < maxLength; col++)
{
topRightPixel = pixels[row][col];
bottomLeftPixel = pixels[col][row];
bottomLeftPixel.setColor(topRightPixel.getColor());
}
}
}
然而,我在某个地方搞砸了,它从图像的右上角反射到左下角
我的问题是:我将如何以其他方式反映它?(更具体地说,从左上到右下)
# 1 楼答案
看起来你认为是右上角的像素实际上是左上角。请尝试以下方法:
# 2 楼答案
你为什么要改变颜色?你可以移动像素对象。此外,如果定义了3种基本转换,则可以通过以不同方式组合前3种来构造所有其他转换。 e、 g