GDI C/C++ - 将 BITMAP 转换为现有的 HBITMAP
如何创建设备上下文兼容的位图,然后将获得的句柄关联到 BITMAP 结构? 如果我写:
...
HBITMAP hbitmap = CreateCompatibleBitmap(hdc, width, height); // these three arguments are initialized somewhere else
hbitmap = CreateBitmapIndirect(bitmap); // argument already initialized and properly filled
...
创建一个与 hdc 兼容的 HBITMAP 句柄,然后初始化一个新的 HBITMAP(填充位图数据),但不保持其兼容性。是否有一个函数允许不从 BITMAP 创建 HBITMAP,而是用现有的 BITMAP 源填充初始化的 HBITMAP?
How can I create a device context compatible bitmap and then associating the obtained handle to a BITMAP struct?
If I write:
...
HBITMAP hbitmap = CreateCompatibleBitmap(hdc, width, height); // these three arguments are initialized somewhere else
hbitmap = CreateBitmapIndirect(bitmap); // argument already initialized and properly filled
...
A HBITMAP handle compatible with hdc is created, and then a new HBITMAP (filled with bitmap data) is initialized, though without keeping its compatibility. Is there a function which allows not to create a HBITMAP from a BITMAP, but rather fills an initialized HBITMAP with an already existing BITMAP source?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CopyImage 函数
创建一张新图像(图标、光标或位图)并将指定图像的属性复制到新图像。如有必要,该函数会拉伸这些位以适合新图像所需的大小。
hImage 要复制的图像的句柄。
uType 要复制的图像的类型。该参数可以是以下值之一。
cxDesired 图像的所需宽度(以像素为单位)。如果为零,则返回的图像将具有与原始 hImage 相同的宽度。
cyDesired 图像的所需高度(以像素为单位)。如果为零,则返回的图像将与原始 hImage 具有相同的高度。
标志位
CopyImage function
Creates a new image (icon, cursor, or bitmap) and copies the attributes of the specified image to the new one. If necessary, the function stretches the bits to fit the desired size of the new image.
hImage A handle to the image to be copied.
uType The type of image to be copied. This parameter can be one of the following values.
cxDesired The desired width, in pixels, of the image. If this is zero, then the returned image will have the same width as the original hImage.
cyDesired The desired height, in pixels, of the image. If this is zero, then the returned image will have the same height as the original hImage.
fuFlags
CreateBitmapIndirect
在其输入上采用BITMAP
。您可以通过GetObject< 获取它来自
HBITMAP
的 /code>:
CreateBitmapIndirect
将能够从此结构创建位图。或者,您可以使用CreateCompatibleBitmap
创建兼容位图,并从获取的Bitmap
提供宽度/高度。CreateBitmapIndirect
takesBITMAP
on its input. And you can get it viaGetObject
fromHBITMAP
:CreateBitmapIndirect
will be able create a bitmap from this struct. Or you can useCreateCompatibleBitmap
to create compatible bitmap providing width/height from obtainedBitmap
.