以下是DdaFindPtImprove函数的完整代码,完整代码,完美运行。
public PointF DdaFindPtImprove(ref byte[] buffer8, PointF Start, PointF End, int thresDelta, int Dir, Size wh, ref int Pos)
{
float x, y;
float dx, dy, k;
PointF backPoint = new PointF();
dx = (float)(End.X - Start.X);
dy = (float)(End.Y - Start.Y);
k = dy / dx;
if (Math.Abs(dx) < 0.001)
{
k = 65535;//随意给定一个最大值,还需论证。20150727
}
x = Start.X;
if (Start.Y < 0) Start.Y = 0;
y = Start.Y;
List<float> temparrclor = new List<float>();
List<PointF> position = new List<PointF>();
#region xiaoyu1
if (Math.Abs(k) < 1)
{
if (x > End.X)
{
for (; x >= End.X; x--)
{
float j = y;
int i = (int)(x);
float tempf = Math.Abs(j - (int)j);
PointF tempPt = new PointF(i, j);
float grey = 0;
if (k > -1 && k <= 0)
{
float avgGrey = (float)buffer8[(int)j * wh.Width + i];
float avgGrey1 = (float)buffer8[((int)j + 1) * wh.Width + i];
grey = avgGrey * (1 - tempf) + avgGrey1 * tempf;
}
else
{
float avgGrey = (float)buffer8[(int)j * wh.Width + i];
float avgGrey1 = (float)buffer8[((int)j - 1) * wh.Width + i];
grey = avgGrey * (1 - tempf) + avgGrey1 * tempf;
}
temparrclor.Add(grey);
position.Add(tempPt);
y = y - k;
}
// backPoint = FindCrosspoint(ref temparrclor, ref position, Dir, thresDelta);
backPoint = FindCrosspointimprove(ref temparrclor, ref position, Dir, thresDelta, ref Pos);//测试纯色区域影响0804
}
else
{
temparrclor.Clear();
position.Clear();
for (; x <= End.X; x++)
{
float j = y;
int i = (int)(x);
float tempf = Math.Abs(j - (int)j);
PointF tempPt = new PointF(i, j);
float grey = 0;
if (k < 1 && k >= 0)
{
float avgGrey = (float)buffer8[(int)j * wh.Width + i];
float avgGrey1 = (float)buffer8[((int)j + 1) * wh.Width + i];
grey = avgGrey * (1 - tempf) + avgGrey1 * tempf;
}
else
{
float avgGrey = (float)buffer8[(int)j * wh.Width + i];
float avgGrey1 = (float)buffer8[((int)j - 1) * wh.Width + i];
grey = avgGrey * (1 - tempf) + avgGrey1 * tempf;
}
temparrclor.Add(grey);
position.Add(tempPt);
y = y + k;
}
// backPoint = FindCrosspoint(ref temparrclor, ref position, Dir, thresDelta);
backPoint = FindCrosspointimprove(ref temparrclor, ref position, Dir, thresDelta, ref Pos);//测试纯色区域影响0804
}
}
#endregion xiaoyu1
#region dayu1
if (Math.Abs(k) >= 1)
{
if (y > End.Y)
{
temparrclor.Clear();
position.Clear();
for (; y >= End.Y; y--)
{
int j = (int)(y);
float i = x;
float tempf = Math.Abs(i - (int)i);
PointF tempPt = new PointF(i, j);
float grey = 0;
if (k > 1)
{
float avgGrey = (float)buffer8[j * wh.Width + (int)i];
float avgGrey1 = (float)buffer8[j * wh.Width + (int)i - 1];
grey = avgGrey * (1 - tempf) + avgGrey1 * tempf;
}
else
{
float avgGrey = (float)buffer8[j * wh.Width + (int)i];
float avgGrey1 = (float)buffer8[j * wh.Width + (int)i + 1];
grey = avgGrey * (1 - tempf) + avgGrey1 * tempf;
}
temparrclor.Add(grey);
position.Add(tempPt);
x = x - 1 / k;
}
// backPoint = FindCrosspoint(ref temparrclor, ref position, Dir, thresDelta);
backPoint = FindCrosspointimprove(ref temparrclor, ref position, Dir, thresDelta, ref Pos);//测试纯色区域影响0804
}
else
{
temparrclor.Clear();
position.Clear();
for (; y <= End.Y; y++)
{
int j = (int)(y);
float i = x;
PointF tempPt = new PointF(i, j);
float tempf = Math.Abs(i - (int)i);
float grey = 0;
if (k < -1)
{
float avgGrey = (float)buffer8[j * wh.Width + (int)i];
float avgGrey1 = (float)buffer8[j * wh.Width + (int)i - 1];
grey = avgGrey * (1 - tempf) + avgGrey1 * tempf;
}
else
{
float avgGrey = (float)buffer8[j * wh.Width + (int)i];
float avgGrey1 = (float)buffer8[j * wh.Width + (int)i + 1];
grey = avgGrey * (1 - tempf) + avgGrey1 * tempf;
}
temparrclor.Add(grey);
position.Add(tempPt);
x = x + 1 / k;
}
// backPoint = FindCrosspoint(ref temparrclor,ref position,Dir,thresDelta);
backPoint = FindCrosspointimprove(ref temparrclor, ref position, Dir, thresDelta, ref Pos); //测试纯色区域影响0804
}
}
#endregion dayu1
return backPoint;
}