CreateCompatibleBitmap Fails with Err code 8
http://www.keyongtech.com/2538297-createcompatiblebitmap-fails-with-err-code
Mahesh Bhirangi
hi,
i am using the follwing calls:
screenDC = GetDC(NULL);
compDC = CreateCompatibleDC(screenDC);
hbmp = CreateCompatibleBitmap(screenDC);
Now if my machine's, display setting if they are at 16, 24 bits per pixel
everything works fine irrespective of resolution setting.
But when i change the bits per pixel setting to 32 and reolution to more
than 1200 * 960. the CreateCompatibleBitmap() starts failing
with error code 8. I have enough virtual memory so that is not the problem.
All suggestions are welcome.
regards
Mahesh
#2 01-21-04, 02:28 PM
Serge Castelier
Did you try
hbmp = CreateCompatibleBitmap(screenDC,GetDeviceCaps(scre enDC, HORZRES),
GetDeviceCaps(screenDC, VERTRES));
Serge
#3 01-21-04, 03:00 PM
Mahesh Bhirangi
yes i m giving the bitmap height and width as arguments.
"Serge Castelier"
<[sdshsh.gs<g<gtzdwhdshdshdsdfhsgqsgqgqgqg[345@]hsdsfdsfhdshsdh[@]qg.qgs][@f
d.com][tyyty.gkjgj[serge.castelier][toot.aar[> wrote
in message news:ik11
[..]
#4 01-21-04, 06:11 PM
vipin
you say 24 bpp works fine and when you cahnge to 32 bpp it fails
for 1200 * 800 the increase in kernel memory is 96KB or 0.1 MB, but you do an
allocation of
0.4 MB. I am not sure whether it should be failing, might be FENG has some
experiences in it
But you could use CreateDibsection to allocate bitmap memory as DIB in user
memory and I am pretty sure i
will work to a bigger scale
thank yo
vipin
#5 01-21-04, 06:12 PM
Feng Yuan [MSFT]
CreateCompatibleBitmap creates DDB, which are normally stored in kernel mode
paged pool. There is a low limit on the kernel mode paged pool, which is
around 48 MB.
Avoid creating lots of DDBs, use DIB section or DIB instead.
#6 01-23-04, 01:06 PM
Marc
I have the same problem like Mahesh
My limitation is around 100MB. All DDBs which are larger than 100MB fail. E.g.
4100x6000 (32Bit)
I will try to use a DIB instead of a DDB.
#7 01-23-04, 05:31 PM
vipin
I think windows NT4 has a bigger range in the kernel memory for DDBs but on
windows 2k and above its just less
#8 01-24-04, 02:59 PM
John Hornick [MSFT]
Hi,
DDBs are generally allocated out of paged pool. This is usually no larger
than 192MB, but can be smaller on systems with less memory, and can be
substantially smaller in Terminal Server environments. If you're
allocating that much at once, you really should be using DIBSections or
DIBs.
Thanks,
- John
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
Visit http://www.microsoft.com/security for current information on security.
> I have the same problem like Mahesh.
My limitation is around 100MB. All DDBs which are larger than 100MB fail.
E.g. 4100x6000 (32Bit).
I will try to use a DIB instead of a DDB.
#9 01-26-04, 07:51 AM
Marc
Ok, now I understand what the problem is
But I have 2 more questions regarding this subject
1. How does Windows create a bitmap for a printer DC? If I get a printer DC
from Windows (e.g. in the OnPrint handler) the bitmap in the DC must be very
large if I have e.g. a plotter paper with DinA1? This must be a large bitmap
2. Do I have the same size limitaion under Windows 95/98/ME (16 MB) if I use a
DIB instead of a DDB
Is it the best way to follow the description in the documentation to create a
DIB with CreateCompatibleBitmap
"If a DIB section, which is a bitmap created by the CreateDIBSection function,
is selected into the device context identified by the hdc parameter,
CreateCompatibleBitmap creates a DIB section.
Maybe someone has some simple example code for this.
#10 01-27-04, 10:31 PM
John Hornick [MSFT]
Hi,
The actual device DC doesn't have a bitmap in it. It's backed by
the device, and doesn't need a memory bitmap.
Win9x is generally more restrictive than NT OSs.
Just use CreateDIBSection() to create the DIBSection.
Thanks,
- John
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
Visit http://www.microsoft.com/security for current information on security.
> Ok, now I understand what the problem is.
But I have 2 more questions regarding this subject:
1. How does Windows create a bitmap for a printer DC? If I get a printer DC
from Windows (e.g. in the OnPrint handler) the bitmap in the DC must be
very large if I have e.g. a plotter paper with DinA1? This must be a large
bitmap.
2. Do I have the same size limitaion under Windows 95/98/ME (16 MB) if I
use a DIB instead of a DDB?
Is it the best way to follow the description in the documentation to create
a DIB with CreateCompatibleBitmap?
"If a DIB section, which is a bitmap created by the CreateDIBSection
function, is selected into the device context identified by the hdc
parameter, CreateCompatibleBitmap creates a DIB section."
Maybe someone has some simple example code for this.
#11 01-28-04, 10:51 AM
Marc
Thank you for your answer.
Win9x is generally more restrictive than NT OSs.
Just use CreateDIBSection() to create the DIBSection.
I have done this and it works fine under NT/2000/XP but that seems not to solve
my problem under ME.
So if ME is so strict (max. 16MB) I will have to find an other solution. Maybe
I have to split my source bitmap into multiple parts and then copy the bands to
my target DC using StretchDIBits.
Is there a "build in" solution in MFC to do this?
#12 01-31-04, 12:31 AM
John Hornick [MSFT]
Hi,
I don't think MFC has anything special to offer here.
I thought I recalled that you could create larger DIBSections on Win9x.
Have you tried it?
Thanks,
- John
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
Visit http://www.microsoft.com/security for current information on security.
> Thank you for your answer.
Win9x is generally more restrictive than NT OSs.
Just use CreateDIBSection() to create the DIBSection.
I have done this and it works fine under NT/2000/XP but that seems not to
solve my problem under ME.
So if ME is so strict (max. 16MB) I will have to find an other solution.
Maybe I have to split my source bitmap into multiple parts and then copy
the bands to my target DC using StretchDIBits.
Is there a "build in" solution in MFC to do this?
#13 01-31-04, 12:56 AM
Severian
On Wed, 28 Jan 2004 03:51:07 -0800, "Marc"
<anonymous> wrote:
>Thank you for your answer.
>
> Win9x is generally more restrictive than NT OSs.
>
> Just use CreateDIBSection() to create the DIBSection.
>
>I have done this and it works fine under NT/2000/XP but that seems not to
solve my problem under ME.
>So if ME is so strict (max. 16MB) I will have to find an other solution. Maybe
I have to split my source bitmap into multiple parts and then copy the bands to
my target DC using StretchDIBits.
>Is there a "build in" solution in MFC to do this?
I'm sure there's no 16Mb limit to DIB sections on ME. I know my
applications creates much larger ones, and it runs fine on ME.
Limits to DDB size may be imposed by the display driver in addition to
the O/S, but (AFAIK) the driver is not involved in DIB sections.
- Sev
#14 02-02-04, 11:26 AM
Marc
Thank you for your help
I have written a small test application which can create DIBs using
CreateCompatibleBitmap (with a DIB already selected into the DC) or
CreateDIBSection and made some tests under Windows ME with a 256 MB PC
If I use CreateDIBSection it seems that I can create very large bitmaps. But
CreateCompatibleBitmap with DIBs seems to be a little bit more restrictiv
But I know I have decided that I use some sort of bitmap banding to do the job.
I devide my large bitmap into smaller bands (chunks) with a size of approx. 8
MB. After I have created each band I use StretchDIBits to copy the band to the
printer DC to its correct position on the output DC. So my memory usage should
be very small
Unfortunately my drawing functions which can create the large bitmap can only
paint the whole bitmap into a DC. So I have to paint the whole bitmap if I want
to paint a band. I use SetViewportOrg to force the drawing function to paint
the part of the bitmap which is my current band.
That leads me to another question: Does GDI paint the whole bitmap if I only
pass a smaller bitmap (= my band) as output to my drawing function? E.g. my
source bitmap is 6000x6000 but I give only a 100x100 bitmap in my output DC in
which the large bitmap is drawn
#15 02-02-04, 02:06 PM
Marc
Thank you for your help.
I have written a small test application which can create DIBs using
CreateCompatibleBitmap (with a DIB already selected into the DC) or
CreateDIBSection and made some tests under Windows ME with a 256 MB PC.
If I use CreateDIBSection it seems that I can create very large bitmaps. But
CreateCompatibleBitmap with DIBs seems to be a little bit more restrictiv.
But I know I have decided that I use some sort of bitmap banding to do the job.
I devide my large bitmap into smaller bands (chunks) with a size of approx. 8
MB. After I have created each band I use StretchDIBits to copy the band to the
printer DC to its correct position on the output DC. So my memory usage should
be very small.
Unfortunately my drawing functions which can create the large bitmap can only
paint the whole bitmap into a DC. So I have to paint the whole bitmap if I want
to paint a band. I use SetViewportOrg to force the drawing function to paint
the part of the bitmap which is my current band.
That leads me to another question: Does GDI paint the whole bitmap if I only
pass a smaller bitmap (= my band) as output to my drawing function? E.g. my
source bitmap is 6000x6000 but I give only a 100x100 bitmap in my output DC in
which the large bitmap is drawn?