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

时间:2023-02-09 22:01:01

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)

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

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

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

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

1 个解决方案

#1


1  

You add the image as the BackgroundImage with BackgroundImageLayout = ImageLayout.Tile and then save the result with DrawToBitmap.

使用BackgroundImageLayout = ImageLayout.Tile将图像添加为BackgroundImage,然后使用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..

为了完全控制,你可以使用DrawImage将多个图像绘制到图像的位图中,但对于你的问题,上面应该做..

#1


1  

You add the image as the BackgroundImage with BackgroundImageLayout = ImageLayout.Tile and then save the result with DrawToBitmap.

使用BackgroundImageLayout = ImageLayout.Tile将图像添加为BackgroundImage,然后使用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..

为了完全控制,你可以使用DrawImage将多个图像绘制到图像的位图中,但对于你的问题,上面应该做..