Link to home
Start Free TrialLog in
Avatar of eugeneng
eugeneng

asked on

cannot create 4096x3072 bitmap!!

I have these code:
void CMyClass ::CreateBitmap()
{
     CDC * pDC = GetDC();
    CBitmap bmp;
    bmp.CreateCompatibleBitmap(pDC,4096,3072);
    ReleaseDC(pDC)
}
but the CreateCompatibleBitmap() return 0, that means the bmp cannot be created. Why?? what's wrong with the code.  Any idea??
Avatar of Zoppo
Zoppo
Flag of Germany image

Hi eugeneng,

check return value of GetLastError() when creation failed.

I guess you'll get an last error 8, which occurs if to less memory is available for an operation. A bitmap of 4096pixel x 3072pixel x 32bit/pixel will need about a 48MB block of continuous free memory.

On my machine the code works, I have 256MB of RAM...

ZOPPO
Avatar of RONSLOW
RONSLOW

btw .. I assume in your real code you actually do something with the bmp .. the code you have just creates the bitmap and then it gets destroyed when bmp goes out of scope.

Perhaps you can change you code so it uses an array of smaller bitmaps?

ceratinly a bitmap of the size your are requesting is pretty goddamn big :-)
hi RONSLOW,

how does using an array of smaller bmp solves the problem? shouldn't they use up the same amount of memory?
 
the problem isn't so much the total amount of memory, it is that it is one big contiguous block.

lots of smaller blicks can be allocate more easily than one big one.
Avatar of eugeneng

ASKER

First of all, I don't have much of other code beside the example above. Then, do you guy notice that, 4096x3072 is actually (1024*4)x(768*4). I'm using 17inc monitor, and my program has a zoom function, which will provide zooming out to 25% of the original picture, therefore I have to create such a goddamn big bitmap.
   But if I use array of bitmap, I still need same amount of memory as the big one right ? eventhought lots of smaller blocks can be allocated more easily that the big one, but I STILL NEED that much of memory right ?
ASKER CERTIFIED SOLUTION
Avatar of RONSLOW
RONSLOW

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
eugeneng,

just for curiosity, do u need to do image processing on that image, such as mosaic, edge enhangement, etc?

... just wondering if it is possible to image process the whole image that has been splitted into an array of image.
The reason I want to use 4 times of screen size for zooming is I don't to redraw my image everytime user changes the zoom setting, because that will take time. Instead, all I want to do is just use StrectBlt() to re-blit the image.

to  leowlf,
no, I do any other process to the image, in fact, I draw everything on a temporary memory DC, and blit the memDC to the screen DC.