Fill picturebox with multiple images and save it. C#

大城市里の小女人 提交于 2019-12-12 07:03:27

问题


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. I can't place image because i don't have enough reputation:(


回答1:


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



来源:https://stackoverflow.com/questions/33848324/fill-picturebox-with-multiple-images-and-save-it-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!