如果 DibSection 独立于任何设备,为什么它需要设备上下文?
If a DibSection is independent of any device, why does it need a device context?
创建位图时有三个四个选择:
- CreateBitmap:创建一个设备相关的位图(最好与您最终打算使用它的设备兼容)
- CreateCompatibleBitmap: 创建一个依赖于设备的位图(与您提供的 DC 兼容)
- CreateDIBitmap: creates a device-dependent bitmap, but lets you specify the device-independent bits to initialize the bitmap with1 (功能上等同于调用 CreateCompatibleBitmap + SetDIBits)
- CreateDIBSection: 创建一个与设备无关的位图(但我必须提供一个 DC?)
为什么 CreateCompatibleBitmap 需要一个 hdc
参数是有道理的:它必须知道要与哪个 DC 兼容。
Note: It doesn't make sense why CreateBitmap doesn't take an hdc
. How does it know what DC to be compatible with?
CreateBitmap doesn't take a DC, and it doesn't know what DC to be compatible with. That's your job. And you better make sure it's compatible with the DC you eventually intended to use it with.
为什么 CreateDIBSection 获取设备上下文句柄?
CreateDIBSection function
The CreateDIBSection function creates a DIB that applications can write to directly. The function gives you a pointer to the location of the bitmap bit values. You can supply a handle to a file-mapping object that the function will use to create the bitmap, or you can let the system allocate the memory for the bitmap.
| Function | Type | Takes hdc |
|------------------------|------|-----------|
| CreateBitmap | DDB | No |
| CreateCompatibleBitmap | DDB | Yes |
| CreateDIBitmap | DDB | Yes |
| CreateDIBSection | DIB | Yes |
DIB 有什么用?
加分题
问。 CreateBitmap 是怎么回事?
一个。由您来确保它兼容。祝你好运!或者你可以只使用 CreateCompatibleBitmap
红利阅读
- 陈百强的老生常谈:A survey of the various ways of creating GDI bitmaps with predefined data。关于在 GDI 中创建位图的不同方法的优秀文章。
答案好像是:
- 仅当
usage = DIB_PAL_COLORS
时才需要 hdc
- 否则(即
usage = DIB_RGB_COLORS
)则hdc
可能是可选的
创建位图时有三个四个选择:
- CreateBitmap:创建一个设备相关的位图(最好与您最终打算使用它的设备兼容)
- CreateCompatibleBitmap: 创建一个依赖于设备的位图(与您提供的 DC 兼容)
- CreateDIBitmap: creates a device-dependent bitmap, but lets you specify the device-independent bits to initialize the bitmap with1 (功能上等同于调用 CreateCompatibleBitmap + SetDIBits)
- CreateDIBSection: 创建一个与设备无关的位图(但我必须提供一个 DC?)
为什么 CreateCompatibleBitmap 需要一个 hdc
参数是有道理的:它必须知道要与哪个 DC 兼容。
Note: It doesn't make sense why CreateBitmap doesn't take anhdc
. How does it know what DC to be compatible with?CreateBitmap doesn't take a DC, and it doesn't know what DC to be compatible with. That's your job. And you better make sure it's compatible with the DC you eventually intended to use it with.
为什么 CreateDIBSection 获取设备上下文句柄?
CreateDIBSection function
The CreateDIBSection function creates a DIB that applications can write to directly. The function gives you a pointer to the location of the bitmap bit values. You can supply a handle to a file-mapping object that the function will use to create the bitmap, or you can let the system allocate the memory for the bitmap.
| Function | Type | Takes hdc |
|------------------------|------|-----------|
| CreateBitmap | DDB | No |
| CreateCompatibleBitmap | DDB | Yes |
| CreateDIBitmap | DDB | Yes |
| CreateDIBSection | DIB | Yes |
DIB 有什么用?
加分题
问。 CreateBitmap 是怎么回事?
一个。由您来确保它兼容。祝你好运!或者你可以只使用 CreateCompatibleBitmap
红利阅读
- 陈百强的老生常谈:A survey of the various ways of creating GDI bitmaps with predefined data。关于在 GDI 中创建位图的不同方法的优秀文章。
答案好像是:
- 仅当
usage = DIB_PAL_COLORS
时才需要 - 否则(即
usage = DIB_RGB_COLORS
)则hdc
可能是可选的
hdc