了解 GetDiBits.C++ [英] Understanding GetDiBits. C++
问题描述
MSDN 说在调用此函数之前,不应将 GetDiBits
中使用的位图选入 DC.但是根据我的经验(使用 BitBlt
),我知道除非选择位图,否则我无法绘制位图.
GetDiBits
如何避免这种情况?我可以只使用一个未选择的、新创建的位图作为这个函数的参数吗?
<块引用>GetDiBits
以及CreateDibSection
返回一个数组.但是 MSDN 说的是第一个函数:指定兼容位图的位"
我认为 DI 代表 DeviceIndependent.为什么会有矛盾?这意味着,根据 MSDN,
GetDiBits
只能与CreateCompatibleBitmap
(即 DD)一起使用?那么我不能把这个数组发送到另一台机器上显示它,对吗?- 这两个函数都使用 hDC.如果
CreateDibSection
是真正的 DIndependent 为什么它需要一个 hDC?所有需要的信息都通过位图信息头提供...
- 除非被选中,否则我无法绘制位图.GetDiBits 如何规避这一点?
GetDIBits 不做任何绘图.它从位图中读取像素数据并将其转换为所需的颜色格式.SetDIBits 也不绘制",但它会在位图中设置像素数据.
<块引用>- 命名混乱.
GetDIBitmap 中的 DI 指的是像素数据以与设备无关的格式(特别是您要求的格式)返回这一事实.源位图可以是兼容位图或与设备无关的位图.
类似地,SetDIBitmap 获取与设备无关的像素数据并将其转换为目标位图的类型.
这些函数的名称令人困惑.
<块引用>- DC 有什么用?
DC 用于回答有关设备上像素格式的任何问题.例如,如果源格式是基于调色板的设备相关位图,GetDIBits 将假定选择到 DC 中的调色板是正确的.请注意,调色板不在 BITMAPINFOHEADER 中.
CreateDIBSection 创建一个混合位图,以独立于设备的方法存储数据,但也可能保持与设备相关的副本与其同步以提高性能.所以它需要知道目标设备的 DC.
MSDN says that the bitmap used in GetDiBits
should not be selected into a DC before calling this function. But from my experience(with BitBlt
) I know that I cannot draw an a bitmap unless it is selected.
- How does
GetDiBits
circumvents this? Can I just use an unselected, newly created bitmap as argument to this function? GetDiBits
as wellCreateDibSection
returns an array. But MSDN says about the first function:"bits of the specified compatible bitmap"
I thought DI stands for DeviceIndependent. Why is there a contradiction? This means that, according to MSDN,
GetDiBits
can be used only withCreateCompatibleBitmap
(which is DD)? Then I can't send this array to another machine to display it,right?- Both functions use a hDC. If
CreateDibSection
is truly DIndependent why does it need a hDC? All the needed info is provided through the bitmapinfoheader...
- I cannot draw an a bitmap unless it is selected. How does GetDiBits circumvents this?
GetDIBits doesn't do any drawing. It reads pixel data from a bitmap and converts it into the desired color format. SetDIBits doesn't "draw" either, but it will set the pixel data in a bitmap.
- Naming confusion.
The DI in GetDIBitmap refers to the fact that the pixel data is returned in a device-independent format (specifically, the one you ask for). The source bitmap can be a compatible bitmap or a device-independent bitmap.
Similarly SetDIBitmap takes device-independent pixel data and converts it to the type of the target bitmap.
These functions are confusingly named.
- What's the DC for?
The DC is used to answer any questions about the pixel format on the device. For example, if the source format is a palette-based device-dependent bitmap, GetDIBits will assume the palette selected into the DC is the correct one. Note that the palette is not in the BITMAPINFOHEADER.
CreateDIBSection creates a hybrid bitmap that stashes data in a device-independent method, but may also keep a device-dependent copy in sync with it for performance. So it needs to know the DC of the intended device.
这篇关于了解 GetDiBits.C++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!