Saving image with backgroundimage to file in C#
I have a picturebox on the form, with BackgroundImage property set to certain image. The rest of the image has certain transparent areas, so that background image is shown in those areas. I want to save it to the file, but there is no save method for p开发者_开发知识库icturebox. There is a save method for image property, but then it only saves the content of the image, and does not include the backgroundimage. Any hints on how I can save both, so that it looks in the file exactly as it looks on the picturebox?
Try:
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height, pictureBox1.CreateGraphics());
bmp.Save(@"BlaBlaBlaBla.Bla");
edit:
Bitmap b = new Bitmap(width, height);
Graphics g = Graphics.FromImage(b);
Then use the drawImage method of Graphics to draw background and foreground and save the bitmap.
I have managed to accomplish this by simply combining two images together using graphics, and then saving the result as a single image object. Thus, I am not using background image anymore.
g.DrawLine(myPen, EX, EY, e.X, e.Y);
EX = e.X;
EY = e.Y;
DrawArea = (Bitmap)pictureBox1.Image.Clone();
pictureBox1.Image = DrawArea;
pictureBox1.Image.Save(@"D:\C#Test_Save_File\Arash_Bashiri.bmp", System.Drawing.Imaging.ImageFormat.Bmp); `
精彩评论