『QQ:1353814576』

GDI+ 多图像按指定行列实现图像合并


使用 Graphics 将n张图像合并成一张宫格图

public class FilmFormat
    {
        public int cols { get; set; }//列数
        public int rows { get; set; }//行数
    }

///多图像按指定行列合并
private Bitmap SplicingMatrix(List<Bitmap> ImageBitmapQueue, FilmFormat Format)
        {
            int CellWidth = (int)(ImageBitmapQueue.Max(e => e.Width));
            int CellHeight = (int)(ImageBitmapQueue.Max(e => e.Height));
            Bitmap bitmap = new Bitmap(Format.cols * CellWidth, Format.rows * CellHeight);
            Graphics g = Graphics.FromImage(bitmap);
            g.SmoothingMode = SmoothingMode.HighSpeed;
            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            g.Clear(Color.Transparent);
            ///Graphics 布局区块 50x50x5
            for (int i = 0; i < ImageBitmapQueue.Count; i++)
            {
                Bitmap MatrixBitmap = ImageBitmapQueue[i];
                MatrixBitmap = new Bitmap(MatrixBitmap, new Size() { Width = MatrixBitmap.Width, Height = MatrixBitmap.Height });
                int row = i / Format.cols;//行数
                int column = i - (row * Format.cols);
                g.DrawImage(MatrixBitmap, new Point() { X = column * CellWidth, Y = row * CellHeight });
            }
            g.Dispose();
            return bitmap;
        }

GDI+ 多图像按指定行列实现图像合并

上效果图

GDI+ 多图像按指定行列实现图像合并