Current location: Hot Scripts Forums » Programming Languages » Windows .NET Programming » [SOLVED] [2005] How to combine PictureBox's Image and BackColor?


[SOLVED] [2005] How to combine PictureBox's Image and BackColor?

Reply
  #1 (permalink)  
Old 04-25-08, 01:29 PM
tim8w tim8w is offline
Wannabe Coder
 
Join Date: Nov 2004
Posts: 183
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy [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?
Reply With Quote
  #2 (permalink)  
Old 04-25-08, 04:26 PM
tim8w tim8w is offline
Wannabe Coder
 
Join Date: Nov 2004
Posts: 183
Thanks: 0
Thanked 0 Times in 0 Posts
Smile 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)
Thanks to AtmaWeapon @ Xtreme VB Talk...
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 02:17 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.