用多个图像填充图片框并保存。 C# [英] Fill picturebox with multiple images and save it. C#

查看:162
本文介绍了用多个图像填充图片框并保存。 C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

PS。我无法放置图片,因为我没有足够的声誉:(

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

推荐答案

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

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);
}

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

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..

这篇关于用多个图像填充图片框并保存。 C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆