Displaying Transparent GIF's

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marge

    Displaying Transparent GIF's

    After importing a VB6 project into Express 2008 I have two gif's with
    transparency do not display correctly.

    In VB6 these pictures where used with the image object which had
    different properties to the picturebox unfortunately there only seems
    to be the picturebox option in the toolbox of Express 2008?

    any ideas/help PLEASE :o)
  • =?Utf-8?B?U3VydHVyWg==?=

    #2
    RE: Displaying Transparent GIF's

    Set the .BackColor to "Transparen t".

    It's at the top of the "Web" tab when you click the BackColor dropdown button.

    --
    David Streeter
    Synchrotech Software
    Sydney Australia


    "Marge" wrote:
    After importing a VB6 project into Express 2008 I have two gif's with
    transparency do not display correctly.
    >
    In VB6 these pictures where used with the image object which had
    different properties to the picturebox unfortunately there only seems
    to be the picturebox option in the toolbox of Express 2008?
    >
    any ideas/help PLEASE :o)
    >

    Comment

    • =?Utf-8?B?U3VydHVyWg==?=

      #3
      RE: Displaying Transparent GIF's

      Hmm. That doesn't actually work.

      Google turns up this: http://www.bobpowell.net/transcontrols.htm

      Look up "ControlSty les Enumeration" in the VB.NET help index, too.

      Doesn't look simple :-(

      --
      David Streeter
      Synchrotech Software
      Sydney Australia


      "SurturZ" wrote:
      Set the .BackColor to "Transparen t".
      >
      It's at the top of the "Web" tab when you click the BackColor dropdown button.
      >
      --
      David Streeter
      Synchrotech Software
      Sydney Australia
      >
      >
      "Marge" wrote:
      >
      After importing a VB6 project into Express 2008 I have two gif's with
      transparency do not display correctly.

      In VB6 these pictures where used with the image object which had
      different properties to the picturebox unfortunately there only seems
      to be the picturebox option in the toolbox of Express 2008?

      any ideas/help PLEASE :o)

      Comment

      • =?Utf-8?B?U3VydHVyWg==?=

        #4
        RE: Displaying Transparent GIF's

        Ugh. Well I got it working, sorta. Add a new class:

        Public Class PanelTransparen t
        Inherits Panel

        Protected Overrides ReadOnly Property CreateParams() As
        System.Windows. Forms.CreatePar ams
        Get
        Dim cp As CreateParams = MyBase.CreatePa rams
        cp.ExStyle = &H20 'WS_EX_TRANSPAR ENT
        Return cp
        End Get
        End Property

        Protected Sub InvalidateEx()
        If Parent Is Nothing Then Exit Sub
        Dim rc As New Rectangle(Me.Lo cation, Me.Size)
        Parent.Invalida te(rc, True)
        End Sub

        Protected Overrides Sub OnPaintBackgrou nd(ByVal e As
        System.Windows. Forms.PaintEven tArgs)
        'do not allow the background to be painted
        End Sub

        Private mimg As Image
        Protected Overrides Sub OnPaint(ByVal e As
        System.Windows. Forms.PaintEven tArgs)
        e.Graphics.Draw Image(mimg, 0, 0)
        End Sub
        Public Sub New(ByVal img As Image)
        mimg = img
        End Sub
        End Class

        You then need to add an instance of the new control at runtime:

        Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
        System.EventArg s) Handles MyBase.Load

        Dim img As Image =
        Bitmap.FromFile (My.Computer.Fi leSystem.Specia lDirectories.De sktop &
        "\pitransgif.gi f")
        Dim pnlTransparent As New PanelTransparen t(img)
        Me.Controls.Add (pnlTransparent )
        pnlTransparent. BringToFront()

        End Sub



        --
        David Streeter
        Synchrotech Software
        Sydney Australia


        "SurturZ" wrote:
        Hmm. That doesn't actually work.
        >
        Google turns up this: http://www.bobpowell.net/transcontrols.htm
        >
        Look up "ControlSty les Enumeration" in the VB.NET help index, too.
        >
        Doesn't look simple :-(
        >
        --
        David Streeter
        Synchrotech Software
        Sydney Australia
        >
        >
        "SurturZ" wrote:
        >
        Set the .BackColor to "Transparen t".

        It's at the top of the "Web" tab when you click the BackColor dropdown button.

        --
        David Streeter
        Synchrotech Software
        Sydney Australia


        "Marge" wrote:
        After importing a VB6 project into Express 2008 I have two gif's with
        transparency do not display correctly.
        >
        In VB6 these pictures where used with the image object which had
        different properties to the picturebox unfortunately there only seems
        to be the picturebox option in the toolbox of Express 2008?
        >
        any ideas/help PLEASE :o)
        >

        Comment

        • Marge

          #5
          Re: Displaying Transparent GIF's

          On 23 Sep, 03:35, SurturZ <surt...@newsgr oup.nospamwrote :
          Ugh. Well I got it working, sorta. Add a new class:
          >
          Public Class PanelTransparen t
              Inherits Panel
          >
              Protected Overrides ReadOnly Property CreateParams() As
          System.Windows. Forms.CreatePar ams
                  Get
                      Dim cp As CreateParams = MyBase.CreatePa rams
                      cp.ExStyle = &H20 'WS_EX_TRANSPAR ENT
                      Return cp
                  End Get
              End Property
          >
              Protected Sub InvalidateEx()
                  If Parent Is Nothing Then Exit Sub
                  Dim rc As New Rectangle(Me.Lo cation, Me.Size)
                  Parent.Invalida te(rc, True)
              End Sub
          >
              Protected Overrides Sub OnPaintBackgrou nd(ByVal e As
          System.Windows. Forms.PaintEven tArgs)
                  'do not allow the background to be painted  
              End Sub
          >
              Private mimg As Image
              Protected Overrides Sub OnPaint(ByVal e As
          System.Windows. Forms.PaintEven tArgs)
                  e.Graphics.Draw Image(mimg, 0, 0)
              End Sub
              Public Sub New(ByVal img As Image)
                  mimg = img
              End Sub
          End Class
          >
          You then need to add an instance of the new control at runtime:
          >
              Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
          System.EventArg s) Handles MyBase.Load
          >
                  Dim img As Image =
          Bitmap.FromFile (My.Computer.Fi leSystem.Specia lDirectories.De sktop &
          "\pitransgif.gi f")
                  Dim pnlTransparent As New PanelTransparen t(img)
                  Me.Controls.Add (pnlTransparent )
                  pnlTransparent. BringToFront()
          >
              End Sub
          >
          --
          David Streeter
          Synchrotech Software
          Sydney Australia
          >
          >
          >
          "SurturZ" wrote:
          Hmm. That doesn't actually work.
          >>
          Look up "ControlSty les Enumeration" in the VB.NET help index, too.
          >
          Doesn't look simple :-(
          >
          --
          David Streeter
          Synchrotech Software
          Sydney Australia
          >
          "SurturZ" wrote:
          >
          Set the .BackColor to "Transparen t".
          >
          It's at the top of the "Web" tab when you click the BackColor dropdown button.
          >
          --
          David Streeter
          Synchrotech Software
          Sydney Australia
          >
          "Marge" wrote:
          >
          After importing a VB6 project into Express 2008 I have two gif's with
          transparency do not display correctly.
          >
          In VB6 these pictures where used with the image object which had
          different properties to the picturebox unfortunately there only seems
          to be the picturebox option in the toolbox of Express 2008?
          >
          any ideas/help PLEASE :o)- Hide quoted text -
          >
          - Show quoted text -
          IS THIS PROGRESS IN BASIC PROGRAMMING?

          all I had to do before was drag an image object onto my form & set its
          properties & tell it which image to use.

          Comment

          • Marge

            #6
            Re: Displaying Transparent GIF's

            On 23 Sep, 03:04, SurturZ <surt...@newsgr oup.nospamwrote :
            Hmm. That doesn't actually work.
            I know, I found that & was hopeful :o)

            Thanks for the bobpowell link but I'm not sure this is the same, what
            he is doings seems much more complicated that what I want to do.

            I have a .gif file which has transparency set, the gif is actually a
            drawn pupil of an eye, black & round with a little white dot for
            reflection. Obviously the image is square so the background is made
            transparent so that when my pupil is added to the face image the
            corners of the pupils are not visible.

            In VB6 the gif was loaded into an image object, VBE does not have an
            image object only picturebox which does not have the same properties
            list.

            Comment

            • Martin H.

              #7
              Re: Displaying Transparent GIF's

              Hello Marge,

              I checked that with a small VB5 project. You are correct that after a
              conversion this problem occurs. It seems that the import assistant
              removes the transparency from the file. If you still have the original
              file, just add it to the PictureBox again (the PictureBox control
              handles transparency correctly). If you do not have it anymore, then you
              would need to save it again and restore the transparency with a graphics
              editor.

              Best regards,

              Martin

              On 22.09.2008 16:14, Marge wrote:
              After importing a VB6 project into Express 2008 I have two gif's with
              transparency do not display correctly.
              >
              In VB6 these pictures where used with the image object which had
              different properties to the picturebox unfortunately there only seems
              to be the picturebox option in the toolbox of Express 2008?
              >
              any ideas/help PLEASE :o)

              Comment

              • rowe_newsgroups

                #8
                Re: Displaying Transparent GIF's

                IS THIS PROGRESS IN BASIC PROGRAMMING?

                Just a casual reminder that Visual Basic .NET is not an update to
                classic Visual Basic (yes, Microsoft marketing may tell you otherwise,
                but I'm more involved with VB than their marketing department is). I
                urge all "new comers" to never think they are working with an updated
                language, but rather an entirely new one.

                With that said, you will find many things you prefer in classic VB,
                but after a while you will grasp the new concepts and start
                likely .NET more than you ever like classic VB.

                Thanks,

                Seth Rowe [MVP]



                Comment

                • Marge

                  #9
                  Re: Displaying Transparent GIF's

                  Replies to:
                  Martin H
                  Tried it does sort of reset the transparency but not quite, there
                  are images on the form in total, 1 large that almost fills the form &
                  2 smaller images which are of pupils for eyes. when the form first
                  runs after conversion all the background colours are very strange, if
                  I right click each image and import them from file loacation
                  everything start to look ok but when I run the pupils which I want to
                  be round are still square images.(tried setting image background
                  colour to webtransparent & setting form transparencyKey to the same
                  but with no luck)

                  rowe_newsgroups ,
                  Yes you are correct I know this is very different, Sorry, Just
                  frustrating at times.


                  I first had a look at VB Express 2008 because I downloaded it onto my
                  sons PC hoping to get him to gain an interest in it, I was pleasantly
                  suprised at some of the new editions so decided to download it for
                  myself too.

                  I got my son to add a couple of images to a form, add a couple of
                  radio buttons and a cmdButton then right the code to change BgColor
                  and select image. I realised today that one of his images was an
                  animated transparent Gif !!!!!!! & it works perfectly :o)

                  Martin H was correct again, it is the import assistant that seems to
                  cause the problem, I decided to remove all trace of the importeed
                  project and recreate it from scratch, that would solve the problem ;o)

                  No, somewhere some how VBExpress seems to know that this very same
                  project once existed before & will not run for multiple errors. :o(

                  My last hope is to remove everting again, restart the PC, recreate the
                  project using completely different file names & obj names but some how
                  I still don't think its going to allow me.

                  Another strange thing was also discovered today, In my desperation I
                  decided to make a VB6 exe of this proj & a VBExpress exe. save them
                  both to seperate folders on a floppy and install them on my sons PC.

                  The VB6 file was just that one item an exe file, I didn't need to
                  install it I could run it from the floppy or just coppy onto hard
                  drive if I wished and run it, no problems at all.

                  The VBExpress version had 3 items, a Apllication files folder,
                  setup.exe, and project1.applic ation. If you click the application or
                  the setup.exe they both do the same and install the program. Clicking
                  the shortcut in star/programes etc runs the program ok with the faulty
                  non transparent gifs.

                  Here is the strange part, normally if you right click a start menu
                  shortcu you can "find target folder" so you can find the exe file, you
                  don't get the option, I also tried to search the whole hard drive for
                  the file name, it did not exsist? I finally went to controlpanel add/
                  remove to remove the program(it was listed there) and I did uninstall
                  it but how can you run an .Exe that doesn't exsist????

                  If anyone is interested in what is causing all this fuss, below is a
                  link to the VB6Exe and an image of the resulting VBExpress project.






                  Comment

                  • =?Utf-8?B?U3VydHVyWg==?=

                    #10
                    Re: Displaying Transparent GIF's

                    If all you are trying to do is layer one image on top of another, you might
                    be better off just drawing them on the same picturebox.

                    Private Sub PictureBox2_Pai nt(ByVal sender As Object, ByVal e As
                    System.Windows. Forms.PaintEven tArgs) Handles PictureBox2.Pai nt
                    Dim imgBG As Image =
                    Bitmap.FromFile (My.Computer.Fi leSystem.Specia lDirectories.De sktop &
                    "\background.gi f")
                    Dim imgFG As Image =
                    Bitmap.FromFile (My.Computer.Fi leSystem.Specia lDirectories.De sktop &
                    "\pitransgif.gi f")
                    PictureBox2.Bac kgroundImage = imgBG
                    e.Graphics.Draw Image(imgFG, New Rectangle(0, 0, imgFG.Width,
                    imgFG.Height))
                    End Sub

                    I tested this and it supports GIF transparency fine. Change the "0, 0" in
                    "New Rectangle(0, 0," to locate the foreground image.

                    I can't believe I didn't suggest this in the first instance. This also
                    allows animation, just call PictureBox2.Ref resh() whenever you want to update
                    the display.

                    Simpler and better than subclassing the Panel control.

                    --
                    David Streeter
                    Synchrotech Software
                    Sydney Australia


                    "Marge" wrote:
                    On 23 Sep, 03:04, SurturZ <surt...@newsgr oup.nospamwrote :
                    Hmm. That doesn't actually work.
                    >
                    I know, I found that & was hopeful :o)
                    >
                    Thanks for the bobpowell link but I'm not sure this is the same, what
                    he is doings seems much more complicated that what I want to do.
                    >
                    I have a .gif file which has transparency set, the gif is actually a
                    drawn pupil of an eye, black & round with a little white dot for
                    reflection. Obviously the image is square so the background is made
                    transparent so that when my pupil is added to the face image the
                    corners of the pupils are not visible.
                    >
                    In VB6 the gif was loaded into an image object, VBE does not have an
                    image object only picturebox which does not have the same properties
                    list.
                    >

                    Comment

                    • Martin H.

                      #11
                      Re: Displaying Transparent GIF's

                      Hello Marge,
                      Tried it does sort of reset the transparency but not quite, there
                      are images on the form in total, 1 large that almost fills the form&
                      2 smaller images which are of pupils for eyes. when the form first
                      runs after conversion all the background colours are very strange, if
                      I right click each image and import them from file loacation
                      everything start to look ok but when I run the pupils which I want to
                      be round are still square images.(tried setting image background
                      colour to webtransparent& setting form transparencyKey to the same
                      but with no luck)
                      I just sent you an e-mail with a small VB.NET Eyes project.
                      I would expect that it should solve your problem.

                      Best regards,

                      Martin

                      Comment

                      • Marge

                        #12
                        Re: Displaying Transparent GIF's

                        On 24 Sep, 02:29, SurturZ <surt...@newsgr oup.nospamwrote :
                        If all you are trying to do is layer one image on top of another, you might
                        be better off just drawing them on the same picturebox.
                        >
                            Private Sub PictureBox2_Pai nt(ByVal sender As Object, ByVal e As
                        System.Windows. Forms.PaintEven tArgs) Handles PictureBox2.Pai nt
                                Dim imgBG As Image =
                        Bitmap.FromFile (My.Computer.Fi leSystem.Specia lDirectories.De sktop &
                        "\background.gi f")
                                Dim imgFG As Image =
                        Bitmap.FromFile (My.Computer.Fi leSystem.Specia lDirectories.De sktop &
                        "\pitransgif.gi f")
                                PictureBox2.Bac kgroundImage = imgBG
                                e.Graphics.Draw Image(imgFG, New Rectangle(0, 0, imgFG.Width,
                        imgFG.Height))
                            End Sub
                        >
                        I tested this and it supports GIF transparency fine. Change the "0, 0" in
                        "New Rectangle(0, 0," to locate the foreground image.
                        >
                        I can't believe I didn't suggest this in the first instance. This also
                        allows animation, just call PictureBox2.Ref resh() whenever you want to update
                        the display.
                        >
                        Simpler and better than subclassing the Panel control.
                        >
                        --
                        David Streeter
                        Synchrotech Software
                        Sydney Australia
                        >
                        I didn't even know you could have more than 1 image per picturebox :o)
                        Thanks I'll have a go at that.

                        Comment

                        Working...