zoukankan      html  css  js  c++  java
  • Image 到 DIB HBITMAP

    HBITMAP ImageToBitmap( Gdiplus::Image* image )
    {
        HDC MemoryDC = ::CreateCompatibleDC(::GetDC(NULL));
    
        UINT height = image->GetHeight();
        UINT width = image->GetWidth();
        if (height <= 0 || width <= 0)
        {
            return NULL;
        }
    
        BITMAPINFO bmpInfo;
        bmpInfo.bmiHeader.biHeight =  -(LONG)height;
        bmpInfo.bmiHeader.biWidth = width;
        bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
        bmpInfo.bmiHeader.biPlanes = 1;
        bmpInfo.bmiHeader.biBitCount = 32;
        bmpInfo.bmiHeader.biCompression = BI_RGB;
        bmpInfo.bmiHeader.biSizeImage = 0;
        bmpInfo.bmiHeader.biXPelsPerMeter = 0;
        bmpInfo.bmiHeader.biYPelsPerMeter = 0;
        bmpInfo.bmiHeader.biClrUsed = 0;
        bmpInfo.bmiHeader.biClrImportant = 0;
        BYTE* pbase = NULL;
        HBITMAP memoryBmp = ::CreateDIBSection(MemoryDC, &bmpInfo, DIB_RGB_COLORS, (void**)&pbase, 0, 0);
        if ( !memoryBmp)
        {
            return NULL;
        }
    
        HBITMAP hOldBmp = (HBITMAP)SelectObject(MemoryDC, memoryBmp);
    
        Gdiplus::Graphics graphics(MemoryDC);
    
        Gdiplus::Rect rect(0, 0, width, height);
        graphics.DrawImage(image, rect);
    
        SelectObject( MemoryDC, hOldBmp);
    
        return memoryBmp;
    }

    老忘记, 记录下

  • 相关阅读:
    golang 中 sync包的 WaitGroup
    Go_20: Golang 中 time 包的使用
    mysql 同步数据到 ElasticSearch 的方案
    mysql 对应 binlog 查看
    python3.6爬虫总结-01
    Golang 之协程详解
    golang私服搭建
    Ubuntu vim设置
    密码校验规则
    golang密码校验
  • 原文地址:https://www.cnblogs.com/dazhu/p/2828732.html
Copyright © 2011-2022 走看看