int lHeight = bmpobj.Height;
int lWidth = bmpobj.Width;
int iRow, iCol;
int radius, angle, x, y;
double a;
int d;
d = Convert.ToInt32(System.Math.Sqrt(lHeight * lHeight + lWidth * lWidth));
double p = 3.1415926 / 180;
int[,] temp = new int[360, d];
for (iRow = 0; iRow < lHeight; iRow++)
{
for (iCol = 0; iCol < lWidth; iCol++)
{
if (bmpobj.GetPixel(iCol, iRow).R < 128)
{
x = iCol;
y = iRow;
for (angle = 0; angle < 360; angle++)
{
a = angle * p;
radius = Convert.ToInt32((double)x * System.Math.Cos(a) + (double)y * System.Math.Sin(a));
temp[angle, radius > 0 ? radius : -radius]++;
}
}
}
}
int max = 0;
int R;
int s = 0, l = 0;
for (iRow = 0; iRow < 360; iRow++)
{
for (iCol = 0; iCol < d; iCol++)
{
if (temp[iRow, iCol] > max)
{
max = temp[iRow, iCol];
s = iRow;
l = iCol;
}
}
}
//bomobj 原始img图片
int w = bmpobj.Width, h = bmpobj.Height;
Bitmap result = new Bitmap(w, h);
using (Graphics g = Graphics.FromImage(result))
{
g.TranslateTransform(w / 2, h / 2);
g.RotateTransform(-1);
g.TranslateTransform(-w / 2, -h / 2);
g.DrawImageUnscaled(bmpobj, 0, 0);
}
result.Save("c://a.bmp");