Understanding GetDiBits. C++

馋奶兔 提交于 2019-12-11 00:24:13

问题


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.

  1. How does GetDiBits circumvents this? Can I just use an unselected, newly created bitmap as argument to this function?
  2. GetDiBits as well CreateDibSection 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 with CreateCompatibleBitmap (which is DD)? Then I can't send this array to another machine to display it,right?

  3. 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...

回答1:


  1. 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.

  1. 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.

  1. 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.



来源:https://stackoverflow.com/questions/49784146/understanding-getdibits-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!