本文为转载文章,但是希望更多的朋友来优化该算法。
旋转算法如下:
Rotation[degrees counterclockwise] | Subscript Manipulation using Pixels |
0 | Out[i, j] = In[i, j] |
90 | Out[j, Right-i-1] = In[i, j] |
180 | Out[Right-i-1, Bottom-j-1] = In[i, j] |
270 | Out[Bottom-j-1,i] = In[i, j] |
i代表x轴的值,j代表Y轴上的值
private
WriteableBitmap
WBRotate(WriteableBitmap wb,
int
CounterclockwiseAngle)
{
int
[,]
wb_arr =
new
int
[wb.PixelWidth,
wb.PixelHeight];
//导致许多缺页中断的初始化循环
//for
(int r = 0; r < wb.PixelHeight; r++)// r=row c=column
//{
//
for (int c = 0; c < wb.PixelWidth; c++)
//
{
//
wb_arr[c, r] = wb.Pixels[wb.PixelWidth * r + c];
//
}
//}
//导致较少缺页中断的初始化循环
对上面代码的简单优化
for
(
int
c
= 0; c < wb.PixelWidth; c++)
//
r=row c=column
{
for
(
int
r
= 0; r < wb.PixelHeight; r++)
{
wb_arr[c,
r] = wb.Pixels[wb.PixelWidth * r + c];
}
}
WriteableBitmap
wb2;
int
[,]
wb_arr_2;
if
(CounterclockwiseAngle
== 0 || CounterclockwiseAngle == 360 || CounterclockwiseAngle == -360)
//0度
360度
{
wb2
=
new
WriteableBitmap(wb.PixelWidth,
wb.PixelHeight);
wb_arr_2
=
new
int
[wb.PixelWidth,
wb.PixelHeight];
wb_arr_2
= wb_arr;
}