用多个图像填充图片框并保存。 C#

时间:2015-11-21 20:38:58

标签: c# image save picturebox fill

我不知道如何多次用小载图像填充图片框然后保存它。 Picturebox的大小由用户决定。然后我加载图像并使用当前大小的图片框将其尽可能多地放到图片框中。 知道怎么做吗? 下面的示例显示它应该是什么样子(但这里有一个背景,我不能在一张图片中保存这些多个图像)

enter image description here

PS。我不能放置图像,因为我没有足够的声誉:(

1 个答案:

答案 0 :(得分:1)

您使用BackgroundImage将图片添加为BackgroundImageLayout = ImageLayout.Tile,然后使用DrawToBitmap保存结果。

pictureBox1.BackgroundImage = someImage;
pictureBox1.BackgroundImageLayout = ImageLayout.Tile;

using (Bitmap bmp = new Bitmap(pictureBox1.ClientSize.Width, 
                               pictureBox1.ClientSize.Height))
{
    pictureBox1.DrawToBitmap(bmp, pictureBox1.ClientRectangle);
    bmp.Save(yourSaveFileName, System.Drawing.Imaging.ImageFormat.Png);
}

要获得完全控制权,您可以使用DrawImage将多个图片绘制到图片的Bitmap,但对于您的问题,上面应该这样做..