[SOLVED] [2005] How to combine PictureBox's Image and BackColor?
OK,
I think I finally know what I need on this. I have a PictureBox with a BackColor set. Then I draw something on the PictureBox. I want to send what I see on the PictureBox, i.e. graphics and BackColor to the ClipBoard. If I just send the PictureBox.Image to the ClipBoard, it draws the graphics correctly, but the background always comes up dark blue. I believe this is because the BackColor is set to be transparent.
How can I combine the Image and BackColor into a bitmap without transparency so that I can send it to the ClipBoard?
Resolved: [2005] How to combine PictureBox's Image and BackColor?
The trivial answer is to do the following:
Code:
' Get the image and the background color
Dim oldImage As Image = pictureBox1.Image
Dim backColor As Color = pictureBox1.BackColor
' make a new image of the appropriate size, and get ready to draw on it
Dim newImage As Image = New Bitmap(oldImage.Width, oldImage.Height, _
Imaging.PixelFormat.Format32bppArgb)
Using g As Graphics = Graphics.FromImage(newImage)
' Draw the background, then the image
Using backBrush As New SolidBrush(backColor)
g.FillRectangle(backBrush, 0, 0, newImage.Width, newImage.Height)
g.DrawImage(oldImage, 0, 0)
End Using
End Using
Clipboard.SetImage(newImage)