我正在尝试为 SQL 解析器创建一个图像,但我遇到了一个障碍,它开始运行非常快,但随着时间的推移,它逐渐变慢,并且内存一直在 60MB 和 300MB 之间波动。对于 3000x3000 的图像,它需要超过 16 个小时......
class Img2Sql
{
static string table_name="test";
static string sql_data="";
public void Start()
{
Console.Write("Enter in a full path to file: ");
String file_full_path = Console.ReadLine();
Bitmap image = AForge.Imaging.Image.FromFile(file_full_path);
Console.WriteLine("Loaded image from File.... {0}\n", file_full_path);
int x = 0;
int y = 0;
int grid_x = image.Width;
int grid_y = image.Height;
Color pix;
for (y = 0; y < grid_y; y++)
{
for (x = 0; x < grid_x; x++)
{
Console.WriteLine("({0},{1})",x,y);
pix = image.GetPixel(x, y);
sql_data += pixel_to_sql(pix, x, y);
//process_slow_destory_max_min(ref pix, ref img, x, y);
}
}
Console.WriteLine(sql_data);
}
static string pixel_to_sql(Color pix,int x,int y)
{
return ("INSERT INTO "+table_name+"(red,green,blue,x,y) VALUES("+pix.R+","+pix.G+","+pix.B+","+x+","+y+");\n");
}
}
这似乎是一个相当直接的循环......