• 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;
    }

    老忘记, 记录下

  • 相关阅读:
    scrapy下载图片第一波
    scrapy之防ban策略
    xml之dtd约束
    Java jdbc相关
    XSS获取cookie
    反射型XSS & DVWA
    MySQL数据库设计规范
    SQL Server 查询指定时间是一年当中的第几周
    js验证15位或18位身份证
    C# Process.Start()
  • 原文地址:https://www.cnblogs.com/dazhu/p/2828732.html
Copyright © 2020-2023  润新知