|
-
March 9th, 2009, 12:22 PM
#1
CreateCompatibleBitmap
Is there a way to obtain the width and height (in pixels) of a DC?
If you take the following code for example:
Code:
HDC memDC = CreateCompatibleDC ( hDC );
HBITMAP memBM = CreateCompatibleBitmap ( hDC, nWidth, nHeight );
SelectObject ( memDC, memBM );
How can I obtain the width and height of hDC so that I can pass the proper values for nWidth and nHeight so that the created bitmap is exactly the same size as the hDC surface?
-
March 9th, 2009, 12:51 PM
#2
Re: CreateCompatibleBitmap
The DC does not have a width or height. It is just an interface for drawing onto a surface.
You have to use some other method to get the dimensions of the window etc. that the DC draws onto.
Nobody cares how it works as long as it works
-
March 9th, 2009, 01:28 PM
#3
Re: CreateCompatibleBitmap
Isn't there a bitmap that is associated with a DC? If so, is there a way for me to access it so that I can get the width and height of the bitmap?
-
March 9th, 2009, 02:58 PM
#4
Re: CreateCompatibleBitmap
You might be able to use GetCurrentObject to get the currently selected bitmap.
Viggy
-
March 10th, 2009, 06:41 AM
#5
Re: CreateCompatibleBitmap
 Originally Posted by links
Isn't there a bitmap that is associated with a DC? If so, is there a way for me to access it so that I can get the width and height of the bitmap?
Not necessarily. A DC with a bitmap is called a memory DC.
Nobody cares how it works as long as it works
-
March 10th, 2009, 01:34 PM
#6
Re: CreateCompatibleBitmap
Thanks for all the replies. You guys are really helpful.
-
March 10th, 2009, 09:52 PM
#7
Re: CreateCompatibleBitmap
There are only 10 types of people in the world:
Those who understand binary and those who do not.
-
March 11th, 2009, 05:36 AM
#8
Re: CreateCompatibleBitmap
 Originally Posted by JohnCz
Well, if I'm not completely mistaken a DC normally draws directly to screen. For instance, GetDC(NULL) will obtain a DC that draws directly on top of the entire screen surface. Such a DC does not have an associated bitmap, and GetCurrentObject would not return anything useful.
If you select a bitmap into the DC, it will draw onto this bitmap instead. Common uses for this are double-buffering (to reduce flicker), but also to generate an image that can be saved to disk. The reason it is called memory DC is that it draws into computer memory rather than a graphics buffer. However, this is not entirely true since device dependent bitmaps very well may be uploaded to the graphics memory for video acceleration purposes. This is done transparently by the system and graphics drivers.
Nobody cares how it works as long as it works
-
March 11th, 2009, 09:18 PM
#9
Re: CreateCompatibleBitmap
 Originally Posted by zerver
A DC with a bitmap is called a memory DC.
Well you stated that DC with bitmap is called memory DC. Not necessarily. You can select bitmap to a window’s device context directly and use it to transfer image.
CreteCompatibleDC, creates device context compatible with window’s device context, in memory; this constitutes so called memory DC or buffer DC. Memory DC is not a specific name that is used for a categorization - it is just most popular.
Created buffer can be used to reduce flickering by transferring image to a buffer, do some drawing and transfer all to a Windows DC. It is also used to store temporally window’s device context to display something else and return to original context.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
-
March 12th, 2009, 02:41 PM
#10
Re: CreateCompatibleBitmap
 Originally Posted by JohnCz
You can select bitmap to a window’s device context directly and use it to transfer image.
Are you sure?
According to MSDN:
Bitmaps can be selected for memory device contexts only, and for only one device context at a time.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
March 15th, 2009, 09:03 AM
#11
Re: CreateCompatibleBitmap
 Originally Posted by VladimirF
Are you sure?
Well, not anymore. That happens when posting without testing. I could have sworn, that I had an application where I selected a bitmap directly to a windows dc, however after finding it, I realized I used BitBlt.
Thanks for correcting and sorry for a confusion.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
-
March 16th, 2009, 08:13 AM
#12
Re: CreateCompatibleBitmap
 Originally Posted by VladimirF
Are you sure?
According to MSDN:
Bitmaps can be selected for memory device contexts only, and for only one device context at a time.
This is correct, although it is possible to work around by creating two device independent bitmaps that share the same pixel memory.
Nobody cares how it works as long as it works
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
|