假设这张图片(fig 1)中的每个像素都是一个数组中的元素。我该如何将它逆时针旋转90度(fig 2)并垂直翻转(fig 3)?
图1:
图2:
图3:
我当前的代码为:
private static Color[][] invert(Color[][] chunk){ //same as rotate
Color[] temp;
for(int i=0;i<chunk.length/2;i++){ //reverse the data
temp=chunk[i];
chunk[i]=chunk[chunk.length-i-1];
chunk[chunk.length-i-1]=temp;
}
return chunk;
}
private static Color[][] rotate(Color[][] chunk){
int cx = chunk.length;
int cz = chunk[0].length;
Color[][] rotated = new Color[cz][cx];
for(int x=0;x<cx;++x){
for(int z=0;z<cz;++z){
rotated[z][x]=chunk[cz-z-1][x];
}
}
return rotated;
}
反相功能与旋转功能相同。需要帮助吗?
result
,并将输入数组中的input[i][j]
条目保存在result[j][i]
条目中。不要对输入数组进行操作! - Baz