Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How do I pick a colour on PictureBox and make it transparent

How do I pick a colour on PictureBox and make it transparent

Scheduled Pinned Locked Moved Visual Basic
questionhelp
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jim Taylor
    wrote on last edited by
    #1

    I would like to be able to pick a colour on a PictureBox control and make it transparent. How can I then save the image as a gif file with transparency. I have a program that draws shapes on an image in a picturebox, however when I save the image none of the shapes that I have drawn are saved. What do I need to do to achieve this. Any help is appreciated. Jim

    J J 2 Replies Last reply
    0
    • J Jim Taylor

      I would like to be able to pick a colour on a PictureBox control and make it transparent. How can I then save the image as a gif file with transparency. I have a program that draws shapes on an image in a picturebox, however when I save the image none of the shapes that I have drawn are saved. What do I need to do to achieve this. Any help is appreciated. Jim

      J Offline
      J Offline
      J Dunlap
      wrote on last edited by
      #2

      OK, first of all, are you drawing the shapes on the PictureBox's Graphics, or a Graphics created from the bitmap? You need to create a graphics from the bitmap using Graphics.FromImage(), and then draw on that. About transparency, I really don't know how to do that with GIFs in GDI+. I believe the first entry in the palette is the transparent color, but I don't know how to set that with GDI+.

      **"Have a heart that never hardens, a temper that never tires, a touch that never hurts." -- Charles Dickens

      FLUID UI Toolkit**

      J 1 Reply Last reply
      0
      • J J Dunlap

        OK, first of all, are you drawing the shapes on the PictureBox's Graphics, or a Graphics created from the bitmap? You need to create a graphics from the bitmap using Graphics.FromImage(), and then draw on that. About transparency, I really don't know how to do that with GIFs in GDI+. I believe the first entry in the palette is the transparent color, but I don't know how to set that with GDI+.

        **"Have a heart that never hardens, a temper that never tires, a touch that never hurts." -- Charles Dickens

        FLUID UI Toolkit**

        J Offline
        J Offline
        Jim Taylor
        wrote on last edited by
        #3

        Thanks for your reply :) In my program the PictureBox is either loaded from a file: pictureBox.Image = Image.FromFile(dlg.FileName) Or from a stream: Dim binaryData(-1) As [Byte] binaryData = Base64Utility.GetByteArray(_ImageData) Dim ms As New MemoryStream(binaryData) _PictureBox.Image = Image.FromStream(ms) To draw on the PictureBox I am calling the Invalidate method which then fires the Paint event: pictureBox.Invalidate() In the paint event I am passing the PaintEventArgs to this Draw Sub. Public Sub Draw(ByVal p As Pen, ByVal e As PaintEventArgs) Implements IHotspot.Draw If _bEndIsSet Then e.Graphics.DrawRectangle(p, New Rectangle(_ptOrigin.X, _ptOrigin.Y, (_ptEnd.X - _ptOrigin.X), (_ptEnd.Y - _ptOrigin.Y))) e.Graphics.DrawRectangle(p, _ptEnd.X - 2, _ptEnd.Y - 2, 4, 4) 'e.Graphics.DrawString(CStr(_ptOrigin.X) & ":" & CStr(_ptOrigin.Y), New Font("arial", 8, FontStyle.Regular), Brushes.Yellow, _ptOrigin.X, _ptOrigin.Y) End If End Sub So instead of using e.Graphics I should be using Graphics.FromImage() to draw on? Jim

        J 1 Reply Last reply
        0
        • J Jim Taylor

          Thanks for your reply :) In my program the PictureBox is either loaded from a file: pictureBox.Image = Image.FromFile(dlg.FileName) Or from a stream: Dim binaryData(-1) As [Byte] binaryData = Base64Utility.GetByteArray(_ImageData) Dim ms As New MemoryStream(binaryData) _PictureBox.Image = Image.FromStream(ms) To draw on the PictureBox I am calling the Invalidate method which then fires the Paint event: pictureBox.Invalidate() In the paint event I am passing the PaintEventArgs to this Draw Sub. Public Sub Draw(ByVal p As Pen, ByVal e As PaintEventArgs) Implements IHotspot.Draw If _bEndIsSet Then e.Graphics.DrawRectangle(p, New Rectangle(_ptOrigin.X, _ptOrigin.Y, (_ptEnd.X - _ptOrigin.X), (_ptEnd.Y - _ptOrigin.Y))) e.Graphics.DrawRectangle(p, _ptEnd.X - 2, _ptEnd.Y - 2, 4, 4) 'e.Graphics.DrawString(CStr(_ptOrigin.X) & ":" & CStr(_ptOrigin.Y), New Font("arial", 8, FontStyle.Regular), Brushes.Yellow, _ptOrigin.X, _ptOrigin.Y) End If End Sub So instead of using e.Graphics I should be using Graphics.FromImage() to draw on? Jim

          J Offline
          J Offline
          J Dunlap
          wrote on last edited by
          #4

          Jim Taylor wrote: So instead of using e.Graphics I should be using Graphics.FromImage() to draw on? Correct. In VB6, you could draw on the picturebox and what you drew would show up on the image, but with VB.NET, this doesn't happen. IMO it's much better that way.

          **"Love does not delight in evil but rejoices with the truth." -- 1 Corinthians 13:6

          FLUID UI Toolkit**

          1 Reply Last reply
          0
          • J Jim Taylor

            I would like to be able to pick a colour on a PictureBox control and make it transparent. How can I then save the image as a gif file with transparency. I have a program that draws shapes on an image in a picturebox, however when I save the image none of the shapes that I have drawn are saved. What do I need to do to achieve this. Any help is appreciated. Jim

            J Offline
            J Offline
            Jim Taylor
            wrote on last edited by
            #5

            If anyone else needs to solve this problem take a look at: Using a Color Matrix to Transform a Single Color and Creating Transparent GIF Images Jim

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups