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. C / C++ / MFC
  4. Copying a HBITMAP to a different HBITMAP

Copying a HBITMAP to a different HBITMAP

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
6 Posts 2 Posters 8 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.
  • C Offline
    C Offline
    Chambers
    wrote on last edited by
    #1

    Hi all (again), I`m stuck (again). I just can`t figure out how to copy a HBITMAP to a completely new HBITMAP (i.e. I don`t want them handling the same image, rather I want a new image which contains the same colours). Anyone know? I`ve tried copying the handle but that doesn`t do what I want it to do (rather obviously) since when I try modifying the new image the old one gets modified too, this is what i *don't* want. I have heard something about memcopy, but haven`t got a clue how I`d use it in conjunction with the HBITMAP and "the bits" of the DIBSection. Any help, or links or ideas or anything = very many thanks. Cheers guys (and gals) Alan.:-D "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

    C 1 Reply Last reply
    0
    • C Chambers

      Hi all (again), I`m stuck (again). I just can`t figure out how to copy a HBITMAP to a completely new HBITMAP (i.e. I don`t want them handling the same image, rather I want a new image which contains the same colours). Anyone know? I`ve tried copying the handle but that doesn`t do what I want it to do (rather obviously) since when I try modifying the new image the old one gets modified too, this is what i *don't* want. I have heard something about memcopy, but haven`t got a clue how I`d use it in conjunction with the HBITMAP and "the bits" of the DIBSection. Any help, or links or ideas or anything = very many thanks. Cheers guys (and gals) Alan.:-D "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

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

      You need to create the second HBITMAP to be the same size, copy them both into DC's and then do a BitBlt between them. If they are both DIBSections, I'd presume you can create the second one the same size as the first and memcpy the bits from one to the other. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

      Sonork ID 100.10002:MeanManOz

      I live in Bob's HungOut now

      C 1 Reply Last reply
      0
      • C Christian Graus

        You need to create the second HBITMAP to be the same size, copy them both into DC's and then do a BitBlt between them. If they are both DIBSections, I'd presume you can create the second one the same size as the first and memcpy the bits from one to the other. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

        Sonork ID 100.10002:MeanManOz

        I live in Bob's HungOut now

        C Offline
        C Offline
        Chambers
        wrote on last edited by
        #3

        Thanks for the response Christian, I would love to be able to memcpy the bits from the one HBITMAP to the other (they will both be DIBSections and they will both be the same size). But how does it work, do I have to create a new HBITMAP first using CreateDIBSection and then use memcpy? If this is correct, how do I use memcpy in that situation, without creating a memory leak from losing the pointers to the original "bits". I would very much like it if you could elaborate a little bit on this direction of solution, Many thanks, again Alan. "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

        C 1 Reply Last reply
        0
        • C Chambers

          Thanks for the response Christian, I would love to be able to memcpy the bits from the one HBITMAP to the other (they will both be DIBSections and they will both be the same size). But how does it work, do I have to create a new HBITMAP first using CreateDIBSection and then use memcpy? If this is correct, how do I use memcpy in that situation, without creating a memory leak from losing the pointers to the original "bits". I would very much like it if you could elaborate a little bit on this direction of solution, Many thanks, again Alan. "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

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

          memcpy copies the contents of the memory, so what happens is this: 1/ You create a new DIBSECTION the same size and bit depth as the first. 2/ You now have two DIBSECTIONs and two pointers to byte arrays, which are the same size. You use memcpy, which copies the contents of one byte array into the other. You're not allocating memory, you're copying the values of the pixels into the location that already holds the values of the bitmap as it was created, making them identical to the first. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

          Sonork ID 100.10002:MeanManOz

          I live in Bob's HungOut now

          C 1 Reply Last reply
          0
          • C Christian Graus

            memcpy copies the contents of the memory, so what happens is this: 1/ You create a new DIBSECTION the same size and bit depth as the first. 2/ You now have two DIBSECTIONs and two pointers to byte arrays, which are the same size. You use memcpy, which copies the contents of one byte array into the other. You're not allocating memory, you're copying the values of the pixels into the location that already holds the values of the bitmap as it was created, making them identical to the first. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

            Sonork ID 100.10002:MeanManOz

            I live in Bob's HungOut now

            C Offline
            C Offline
            Chambers
            wrote on last edited by
            #5

            Many thanks Christian, I`m off to implement your suggestion, I`ll get back to you and amend this message with the results. Thanking you lots, Alan. "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

            C 1 Reply Last reply
            0
            • C Chambers

              Many thanks Christian, I`m off to implement your suggestion, I`ll get back to you and amend this message with the results. Thanking you lots, Alan. "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

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

              No worries - glad to help. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

              Sonork ID 100.10002:MeanManOz

              I live in Bob's HungOut now

              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