Skylin R Skylin R - 1 month ago 24
C# Question

Fill picturebox with multiple images and save it. C#

I don't know how to fill picturebox with small loaded image multiple times and then save it.
Picturebox has a size determined by user. Then I load the image and put it to picturebox as many times as possible with current size of picturebox.
Any idea how to do that?
Example bellow shows how it should look like (but here there is a background and i cant save this multiple images in one picture)

enter image description here

PS. I can't place image because i don't have enough reputation:(

TaW TaW
Answer

You add the image as the BackgroundImage with BackgroundImageLayout = ImageLayout.Tile and then save the result with 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);
}

For full control you would use DrawImage to draw multiple images into the Bitmap of the Image, but for your question the above should do..