Copying a HBITMAP to a different HBITMAP
-
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:
-
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:
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
-
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
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:
-
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:
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
-
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
-
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:
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