从剪贴板获取CF_DIBV5的位图 [英] Get bitmap of a CF_DIBV5 from clipboard

查看:136
本文介绍了从剪贴板获取CF_DIBV5的位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从剪贴板中获取位图数据。我可以成功获取 CF_DIBV5 对象的标题信息:

I'm trying to get bitmap data from the clipboard. I can successfully get the header information for the CF_DIBV5 object:

    BOOLEAN exists = IsClipboardFormatAvailable(CF_DIBV5) &&
        OpenClipboard(session->windowHandle);

    if (exists) {
        HGLOBAL clipboard = GetClipboardData(CF_DIBV5);
        exists = clipboard != NULL;
        if (exists) {
            LPTSTR lptstr = GlobalLock(clipboard);
            exists = lptstr != NULL;
            if (exists) {
                BITMAPV5HEADER * header = clipboard;
                //now need the HBITMAP!
            }
        }
    }
    //...

我可以成功地从标题中记录信息。现在,我需要实际的 HBITMAP ,以便将其传递到 GetDIBits 中。文档说 CF_DIBV5 BITMAPV5HEADER 后跟位图颜色空间信息和位图位。

I can successfully log info from the header. Now I want the actual HBITMAP so I can pass it into GetDIBits. The docs say CF_DIBV5 is a BITMAPV5HEADER "followed by the bitmap color space information and the bitmap bits".

最后一部分使我感到困惑,因为它使用的是简单的英语。我假设要获取位图位,我需要将标头的大小和颜色空间信息添加到标头指针。因此

That last part confuses me ironically because it's in plain English. I assume to get to the bitmap bits, I need to add the size of the header and the "color space information" to the header pointer. So

HBITMAP bitmap = header + sizeof(BITMAPV5HEADER) + /* ???? */;

我认为...

如何我能知道这个神秘色彩空间信息的大小吗?而且,位图位从字面上看是否是HBITMAP,因此上面的表达式是正确的?

How can I know the size of this mysterious color space information? And are the "bitmap bits" literally an HBITMAP such that the above expression would be true?

由于我是C新手,所以我可能会忽略这一点。

I may be overlooking the obvious since I am a C newbie.

更新:现在,通过试验和重新阅读一些文档,我意识到 HBITMAP 是DDB,而我有一个DIB。所以 GetDIBits 对我来说不是正确的功能。可以使用什么函数将任何DIB转换为不压缩的格式?

Update: I now realize from experimenting and rereading some documentation that an HBITMAP is a DDB, whereas I have a DIB. So GetDIBits is not the right function for me. What function can be used to convert any DIB to a format with no compression?

推荐答案

以下是如何获取指向位图位。内容的排列取决于标题中描述的压缩类型和位数。

Here's how to get the appropriate pointer to the bitmap bits. The arrangement of the contents depends on the compression type and bit count described in the header.

HGLOBAL clipboard = GetClipboardData(CF_DIBV5);
BITMAPV5HEADER* bitmapV5Header = (BITMAPV5HEADER*)GlobalLock(clipboard);
int offset = bitmapV5Header->bV5Size + bitmapV5Header->bV5ClrUsed * sizeof(RGBQUAD);
if (bitmapV5Header->bV5Compression == BI_BITFIELDS)
    offset += 12; //bit masks follow the header
BYTE *bits = (BYTE*)bitmapV5Header + offset;

这篇关于从剪贴板获取CF_DIBV5的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆