圖像旋轉是指把定義的圖像繞某一點以逆時針或順時針方向旋轉必定的角度,一般是指繞圖像的中心以逆時針方向旋轉。top
假設圖像的左上角爲(left, top),右下角爲(right, bottom),則圖像上任意點(x0, y0)繞其中心(xcenter, ycenter)逆時針旋轉angle角度後,新的座標位置(x′, y′)的計算公式爲:co
xcenter = (right - left + 1) / 2 + left;
ycenter = (bottom - top + 1) / 2 + top;
x′ = (x0 - xcenter) cosθ - (y0 - ycenter) sinθ + xcenter;
y′ = (x0 - xcenter) sinθ + (y0 - ycenter) cosθ + ycenter;鏡像
與圖像的鏡像變換相相似,也採用按行逐點變換的方式實現圖像的旋轉