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. Option strict ON problem ..

Option strict ON problem ..

Scheduled Pinned Locked Moved Visual Basic
helpgraphicsquestion
7 Posts 3 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.
  • G Offline
    G Offline
    Georg Kohler
    wrote on last edited by
    #1

    I can not figure out how load the file into my bitmap without getting an error with Option Strict set to ON (It works fine with Option Strict OFF ..:-)) Public BitmapImage As Bitmap BitmapImage = Bitmap.FromFile(filename) ' where file name is soemthing like ' "C:\Project\Prolasspecial.bmp" What's the "correct" way of coding this, so that Option Strict On will not complain :rolleyes: ?? Georg

    C S 2 Replies Last reply
    0
    • G Georg Kohler

      I can not figure out how load the file into my bitmap without getting an error with Option Strict set to ON (It works fine with Option Strict OFF ..:-)) Public BitmapImage As Bitmap BitmapImage = Bitmap.FromFile(filename) ' where file name is soemthing like ' "C:\Project\Prolasspecial.bmp" What's the "correct" way of coding this, so that Option Strict On will not complain :rolleyes: ?? Georg

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Option Strict OFF is the same as 'I am not a programmer'. The problem is simple. Bitmap.FromFile returns an image, not a bitmap. Yes, this is stupid.

      Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

      G S 2 Replies Last reply
      0
      • C Christian Graus

        Option Strict OFF is the same as 'I am not a programmer'. The problem is simple. Bitmap.FromFile returns an image, not a bitmap. Yes, this is stupid.

        Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

        G Offline
        G Offline
        Georg Kohler
        wrote on last edited by
        #3

        I understand that .fromFile returns an Image = question remains what's the correct function to use to load my Bitmap file into my bitmap ?? How do I Convert it? I goggled it - but it seems everybody else has figured this one out or the offered solutions seem rather "complicated" to me Im I using the wrong Load function ? Is there a direct conversion from Image to Bitmap? Whats the "proper" way of doing this? Do I need to load it into an Image first and then use a conversion ??? Georg

        1 Reply Last reply
        0
        • G Georg Kohler

          I can not figure out how load the file into my bitmap without getting an error with Option Strict set to ON (It works fine with Option Strict OFF ..:-)) Public BitmapImage As Bitmap BitmapImage = Bitmap.FromFile(filename) ' where file name is soemthing like ' "C:\Project\Prolasspecial.bmp" What's the "correct" way of coding this, so that Option Strict On will not complain :rolleyes: ?? Georg

          S Offline
          S Offline
          Scott Dorman
          wrote on last edited by
          #4

          The Bitmap class has a constructor that takes a path to a file and a constructor which takes an image. The best option would be something like this:

          Public BitmapImage As Bitmap

          BitmapImage = New Bitmap(filename)

          ' or

          BitmapImage = New Bitmap(Bitmap.FromFile(filename))

          I think the first option is simpler.

          Scott Dorman

          Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]


          Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

          G 1 Reply Last reply
          0
          • C Christian Graus

            Option Strict OFF is the same as 'I am not a programmer'. The problem is simple. Bitmap.FromFile returns an image, not a bitmap. Yes, this is stupid.

            Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

            S Offline
            S Offline
            Scott Dorman
            wrote on last edited by
            #5

            Christian Graus wrote:

            The problem is simple. Bitmap.FromFile returns an image, not a bitmap. Yes, this is stupid.

            Well...not entirely since FromFile is actually inherited from the Image class.

            Scott Dorman

            Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]


            Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

            1 Reply Last reply
            0
            • S Scott Dorman

              The Bitmap class has a constructor that takes a path to a file and a constructor which takes an image. The best option would be something like this:

              Public BitmapImage As Bitmap

              BitmapImage = New Bitmap(filename)

              ' or

              BitmapImage = New Bitmap(Bitmap.FromFile(filename))

              I think the first option is simpler.

              Scott Dorman

              Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]


              Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

              G Offline
              G Offline
              Georg Kohler
              wrote on last edited by
              #6

              Thanks - you guys are great! I knew there had to be a simple solution .... ;) georg

              S 1 Reply Last reply
              0
              • G Georg Kohler

                Thanks - you guys are great! I knew there had to be a simple solution .... ;) georg

                S Offline
                S Offline
                Scott Dorman
                wrote on last edited by
                #7

                Georg Kohler wrote:

                Thanks - you guys are great! I knew there had to be a simple solution ....

                You're welcome. Best place to look first is always the documentation. :)

                Scott Dorman

                Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]


                Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

                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