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. Graphics
  4. convert image to bitmap

convert image to bitmap

Scheduled Pinned Locked Moved Graphics
graphicshelp
10 Posts 5 Posters 24 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.
  • D Offline
    D Offline
    dogmatic69
    wrote on last edited by
    #1

    Hi, Is there a way to convert a system.drawing.image to system.drawing.bitmap without having to save it to disk first. Would appreciate any good help thanks

    M 1 Reply Last reply
    0
    • D dogmatic69

      Hi, Is there a way to convert a system.drawing.image to system.drawing.bitmap without having to save it to disk first. Would appreciate any good help thanks

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      There's three System.Drawing.Bitmap constructors that take a System.Drawing.Image as a parameter... Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      D 1 Reply Last reply
      0
      • M Mark Salsbery

        There's three System.Drawing.Bitmap constructors that take a System.Drawing.Image as a parameter... Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        D Offline
        D Offline
        dogmatic69
        wrote on last edited by
        #3

        Hi, thanks for the reply. Im new with C# (started with TP and mainly work in php / MySQL) so constructors is all new to me... Been looking around and cant seem to find the right thing/way to do this. if i have System.Drawing.Image modimage; System.Drawing.Bitmap modbitmap; changes are first done to modimage and then i want to do something like modbitmap = modimage; and then carry on with changes to modbitmap. obviously the modbitmap = modimage; does not work as it is like trying to say strSomething = intSomethign; it would be nice if there was a thing like modbitmap = modimage.tobitmap(); lol anyway, my trials have proved fruitless so i am hoping that you would be kind enough to spare a min and help me out. thanks in advance.:cool:

        G M M 3 Replies Last reply
        0
        • D dogmatic69

          Hi, thanks for the reply. Im new with C# (started with TP and mainly work in php / MySQL) so constructors is all new to me... Been looking around and cant seem to find the right thing/way to do this. if i have System.Drawing.Image modimage; System.Drawing.Bitmap modbitmap; changes are first done to modimage and then i want to do something like modbitmap = modimage; and then carry on with changes to modbitmap. obviously the modbitmap = modimage; does not work as it is like trying to say strSomething = intSomethign; it would be nice if there was a thing like modbitmap = modimage.tobitmap(); lol anyway, my trials have proved fruitless so i am hoping that you would be kind enough to spare a min and help me out. thanks in advance.:cool:

          G Offline
          G Offline
          GrinderDev
          wrote on last edited by
          #4

          Try this: modbitmap = new System.Drawing.Bitmap(modimage);

          1 Reply Last reply
          0
          • D dogmatic69

            Hi, thanks for the reply. Im new with C# (started with TP and mainly work in php / MySQL) so constructors is all new to me... Been looking around and cant seem to find the right thing/way to do this. if i have System.Drawing.Image modimage; System.Drawing.Bitmap modbitmap; changes are first done to modimage and then i want to do something like modbitmap = modimage; and then carry on with changes to modbitmap. obviously the modbitmap = modimage; does not work as it is like trying to say strSomething = intSomethign; it would be nice if there was a thing like modbitmap = modimage.tobitmap(); lol anyway, my trials have proved fruitless so i am hoping that you would be kind enough to spare a min and help me out. thanks in advance.:cool:

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            Try what GrinderDev suggested ;) Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            1 Reply Last reply
            0
            • D dogmatic69

              Hi, thanks for the reply. Im new with C# (started with TP and mainly work in php / MySQL) so constructors is all new to me... Been looking around and cant seem to find the right thing/way to do this. if i have System.Drawing.Image modimage; System.Drawing.Bitmap modbitmap; changes are first done to modimage and then i want to do something like modbitmap = modimage; and then carry on with changes to modbitmap. obviously the modbitmap = modimage; does not work as it is like trying to say strSomething = intSomethign; it would be nice if there was a thing like modbitmap = modimage.tobitmap(); lol anyway, my trials have proved fruitless so i am hoping that you would be kind enough to spare a min and help me out. thanks in advance.:cool:

              M Offline
              M Offline
              Matthew Butler 0
              wrote on last edited by
              #6

              You could also just cast it... (This is a bit faster and uses less memory). bitmap = (Bitmap)image;


              Matthew Butler

              L 1 Reply Last reply
              0
              • M Matthew Butler 0

                You could also just cast it... (This is a bit faster and uses less memory). bitmap = (Bitmap)image;


                Matthew Butler

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                Yes, most of the time that will work; what if the image happens to be a Metafile? :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


                M 1 Reply Last reply
                0
                • L Luc Pattyn

                  Yes, most of the time that will work; what if the image happens to be a Metafile? :)

                  Luc Pattyn [Forum Guidelines] [My Articles]


                  this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


                  M Offline
                  M Offline
                  Matthew Butler 0
                  wrote on last edited by
                  #8

                  I've never used metafiles. ...but I suppose that would give an error. Do people still use wmf/emf? I've always concidered them quite an old (and outdated) format.


                  Matthew Butler

                  L 1 Reply Last reply
                  0
                  • M Matthew Butler 0

                    I've never used metafiles. ...but I suppose that would give an error. Do people still use wmf/emf? I've always concidered them quite an old (and outdated) format.


                    Matthew Butler

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #9

                    M. Butler wrote:

                    Do people still use wmf/emf?

                    I don't know. My point is: (Bitmap)Image.FromFile("test.WMF") could throw since there is a difference between Bitmap and Image classes, so I prefer either the constructor approach (hoping it is not too expensive) or an "is Bitmap" test (C#). :)

                    Luc Pattyn [Forum Guidelines] [My Articles]


                    this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


                    M 1 Reply Last reply
                    0
                    • L Luc Pattyn

                      M. Butler wrote:

                      Do people still use wmf/emf?

                      I don't know. My point is: (Bitmap)Image.FromFile("test.WMF") could throw since there is a difference between Bitmap and Image classes, so I prefer either the constructor approach (hoping it is not too expensive) or an "is Bitmap" test (C#). :)

                      Luc Pattyn [Forum Guidelines] [My Articles]


                      this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


                      M Offline
                      M Offline
                      Mark Salsbery
                      wrote on last edited by
                      #10

                      Good example of why casts are dangerous. C# really allows casts? hehe

                      Mark Salsbery Microsoft MVP - Visual C++ :java:

                      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