public Bitmap Apply(List<Bitmap> srcimg_list, int max_width)
{
for (int i = 0; i < srcimg_list.Count; i++)
{
if (cell_height < srcimg_list[i].Height)
cell_height = srcimg_list[i].Height;
if (cell_width < srcimg_list[i].Width)
cell_width = srcimg_list[i].Width;
}
cell_width += 10;
cell_height += 10;
cols = max_width / cell_width;
rows = srcimg_list.Count / cols + 1;
int image_width = cols * cell_width;
int image_height = rows * cell_height;
Bitmap string_img = new Bitmap(image_width, image_height);
Graphics g = Graphics.FromImage(string_img);
g.Clear(Color.White);
for (int r = 0; r < rows; r++)
g.DrawLine(new Pen(Color.Black, 3), new Point(0, r * cell_height), new Point(image_width, r * cell_height));
for (int c = 0; c < cols; c++)
g.DrawLine(new Pen(Color.Black), new Point(c * cell_width, 0), new Point(c * cell_width, image_height));
for (int r = 0; r < rows; r++)
for (int c = 0; c < cols; c++)
{
int idx = r * cols + c;
if (idx >= srcimg_list.Count) continue;
int margin = 4;
int w = cell_width - srcimg_list[idx].Width - margin;
w /= 2;
int h = cell_height - srcimg_list[idx].Height - margin;
h /= 2;
g.DrawImage(srcimg_list[idx],
new Point(c * cell_width + w, r * cell_height + h));
}
g.Dispose();
return string_img;
}