However, the CopyImage method often fails and GetLastError returns 8 which means "not enough memory". What confuses me the most is that after this unsuccessful call I can happily create other bitmaps of the same size with the CreateCompatibleBitmap method. When there is not enough memory to copy a bitmap, shouldn't there be also not enough memory to create it? Or is there any other reason why CopyImage fails?
Don't know what the cause of your problem is, but why not use bitblt. I never even heard of CopyImage. Always used bitblt.
I don't want to put the bitmap to a DC (to display it somewhere). I need to copy the bitmap data in the memory, so that I have two independent copies of it.
I have always used BitBlt() too, but CopyImage() looks interesting.
It is said, at http://www.codeproject.com/Messages/...mage-woes.aspx , that the color depth must be the same for the source and target image. I am not sure that your last argument, LR_MONOCHROME, is correct. Can you try with something else? e.g. LR_CREATEDIBSECTION.
Last edited by olivthill2; January 28th, 2010 at 04:27 AM.
This http://support.microsoft.com/kb/935607 could be an answer to your problem. Even if the description provided by MS would indicate otherwise since the color depth is just 1 bit.
I have always used BitBlt() too, but CopyImage() looks interesting.
It is said, at http://www.codeproject.com/Messages/...mage-woes.aspx , that the color depth must be the same for the source and target image. I am not sure that your last argument, LR_MONOCHROME, is correct. Can you try with something else? e.g. LR_CREATEDIBSECTION.
I tried setting the flags to zero, with no effect. And now I'm even more confused - the program created and successfully copied 95 bitmaps. Then it created two more, the CopyImage method returned a non-NULL handle for them, but GetLastError called immediately after it returned 8! From then on, the program was able to create the bitmaps but CopyImage always returned NULL and GetLastError returned 8. What's going on?
This http://support.microsoft.com/kb/935607 could be an answer to your problem. Even if the description provided by MS would indicate otherwise since the color depth is just 1 bit.
Thanks for an interesting link, but I am running Windows XP
Another update: when I try using a DIB instead of a DDB (by calling CreateDIBSection instead of CreateCompatibleBitmap), CopyImage always passes but GetLastError after it returns always 8.
Could be you're running into a limitation of GDI. And yes, even on XP there are still limits on certain GDI/USER/Kernel resources.
My guess is that you're hitting the limit of either bitmap handles, bitmap headers (which use memory in the global GDI space) combined with the fact that CopyImage needs a temporary buffer for the image rescaling (Even if you're not actually rescaling).
Why do you need an actual copy of the bitmap ? As far as windows is concerned, there's no real reason to actually ever have a duplicate. If you're not painting on it, why does it even matter ?
Bookmarks