-
January 28th, 2010, 03:18 AM
#1
Why does CopyImage fail?
Hi, in my program I create several dozen of quite big monochrome bitmaps (approx. 6000 x 1500 pixels). This is done in a standard way by calling
Code:
CBitmap bmp;
bmp.CreateCompatibleBitmap( &memDC, bitmapWidth, bitmapHeight);
where memDC is obviously a memory DC. I need then to copy the bitmap and get a new handle. I do this by calling
Code:
HBITMAP hBitmapNew = (HBITMAP) CopyImage( (HBITMAP) bmp.GetSafeHandle(), IMAGE_BITMAP, 0, 0, LR_MONOCHROME );
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?
-
January 28th, 2010, 03:38 AM
#2
Re: Why does CopyImage fail?
Don't know what the cause of your problem is, but why not use bitblt. I never even heard of CopyImage. Always used bitblt.
-
January 28th, 2010, 03:54 AM
#3
Re: Why does CopyImage fail?
Originally Posted by Skizmo
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.
-
January 28th, 2010, 05:25 AM
#4
Re: Why does CopyImage fail?
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 05:27 AM.
-
January 28th, 2010, 06:00 AM
#5
Re: Why does CopyImage fail?
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.
-
January 28th, 2010, 06:06 AM
#6
Re: Why does CopyImage fail?
Originally Posted by olivthill2
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?
-
January 28th, 2010, 06:56 AM
#7
Re: Why does CopyImage fail?
Originally Posted by OReubens
Thanks for an interesting link, but I am running Windows XP
-
January 28th, 2010, 07:31 AM
#8
Re: Why does CopyImage fail?
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.
-
January 28th, 2010, 07:55 AM
#9
Re: Why does CopyImage fail?
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 ?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|