is there any way to save a picturebox (Windows Forms) with it Backgroundimage to a file? I tried to store the picturebox.Image into a bitmap but its only the image itself, not the backgroundimage too.
Asked
Active
Viewed 222 times
-2
-
2Does this answer your question? [Saving image with backgroundimage to file in C#](https://stackoverflow.com/questions/6633103/saving-image-with-backgroundimage-to-file-in-c-sharp) See the accepted answer. – Code Stranger Jun 04 '21 at 16:12
-
1Save the background image to bitmap first, then draw the other image on top of it – Ňɏssa Pøngjǣrdenlarp Jun 04 '21 at 16:16
-
1Or you could use DrawToBitmap, which will also save any graphics you draw in the Paint event.. – TaW Jun 04 '21 at 16:34
-
@TaW but DrawToBitmap isnt transparent, right? I want to save it as a PNG. Thanks for all the help! – Slim Ontario Jun 04 '21 at 18:50
-
Not sure atm. If you create a transparent bitmap it should faithfully recreate the pbox.. – TaW Jun 04 '21 at 19:20
1 Answers
1
You can combine two images using graphics or bitmap. There is a good example provided here
Bitmap
using (var bitmap = new Bitmap(@"Images\in.jpg"))
using (var watermark = new Bitmap(@"Images\watermark.png"))
{
//Make the watermark semitransparent.
watermark.Channels.ScaleAlpha(0.8F);
//Watermark image
bitmap.Draw(watermark, 10, bitmap.Height - watermark.Height - 40, CombineMode.Alpha);
//Save the resulting image
bitmap.Save(@"Images\Output\out.jpg");
}
Graphics:
using (var bitmap = new Bitmap(@"Images\in.jpg"))
using (var watermark = new Bitmap(@"Images\watermark.png"))
{
//Make the watermark semitransparent.
watermark.Channels.ScaleAlpha(0.8F);
//Watermark an image.
using (var graphics = bitmap.GetGraphics())
{
graphics.DrawImage(watermark, 10, bitmap.Height - watermark.Height - 40, CombineMode.Alpha);
//Save the resulting image
bitmap.Save(@"Images\Output\out.jpg");
}
}

Boris Sokolov
- 1,723
- 4
- 23
- 38