简体   繁体   English

C ++中的GDI + GdipCreateBitmapFromHBITMAP

[英]GDI+ GdipCreateBitmapFromHBITMAP in C++

here is my function im trying to create bitmap from hbitmap here. 这是我的功能,我试图从hbitmap创建位图。 But im getting identifier not found error. 但是,我正在获取标识符未找到错误。

    __declspec(dllexport) void __stdcall testFunction()
{
    int W = 860, H = 720;

    int iLeft = 0, iRight = 860;
    int iTop = 0, iBottom = 720;

    int iW = iRight - iLeft, iH = iBottom - iTop;

    HWND bluestacks =  FindWindow(L"BlueStacksApp", L"BlueStacks App Player");
    HDC bHDC = GetWindowDC(bluestacks);
    HDC cHDC = CreateCompatibleDC(bHDC);
    HBITMAP bmp = CreateCompatibleBitmap( bHDC, W, H);

    HGDIOBJ sO =  SelectObject( cHDC, bmp);
    BOOL pW =PrintWindow( bluestacks, cHDC, 0);
    SelectObject(cHDC, bmp);
    BitBlt(cHDC, 0, 0, iW, iH, bHDC, iLeft, iTop, 0x00CC0020);
    Bitmap newBitmap = GdipCreateBitmapFromHBITMAP(bmp);

}

Error code: 错误代码:

identifier "GdipCreateBitmapFromHBITMAP" is undefined 标识符“ GdipCreateBitmapFromHBITMAP”未定义

Note loaded header files: 注意加载的头文件:

    #include <stdio.h>
#include <windows.h>
#include <iostream>
#include <string.h>
#include <strsafe.h>
#include <gdiplus.h>
#include <Gdiplusflat.h> // Gdiplusflat.h
#include <ostream>

The function is defined as follows: 该函数定义如下:

GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm,
                        HPALETTE hpal,
                        GpBitmap** bitmap);

if you want to get a Bitmap object from a HBITMAP, maybe you shoud use the constructor 如果要从HBITMAP获取Bitmap对象,也许应该使用构造函数

Bitmap(HBITMAP,HPALETTE);

for your code it should be: 为您的代码应该是:

Bitmap newBitmap(bmp,NULL);

BTW:before use this, you should initialize GDIPLUS. 顺便说一句:使用此功能之前,您应该初始化GDIPLUS。

为链接器-lgdiplus -mwindows添加其他选项后,对我-lgdiplus -mwindows

g++ test.c -lgdiplus -mwindows

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM