說在這張照片(圖1)的每個像素是在陣列中的元素。我將如何逆時針旋轉90度(圖2)並垂直翻轉(圖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;
}
的反相確實相同的功能的旋轉雖然。任何幫助?
:TEMP =塊[i] [j]塊[i] [j] =塊[j]的[I]; chunk [j] [i] = temp;但它沒有做任何不同的事情,部分仍然是一樣的。幫幫我? – jocopa3
創建一個新數組'result'並將輸入數組的'input [i] [j]'條目保存到'result [j] [i]'條目中。不要在輸入數組上工作! – Baz