• 利用GDI+加载图片


    #include <comdef.h>
    #ifndef ULONG_PTR
    #define ULONG_PTR unsigned long*
    #include "GdiPlus.h"
    using namespace Gdiplus;
    #endif
    #pragma comment(lib,"gdiplus.lib")
    
    HBITMAP CreateBitmapFromImage( LPCTSTR pFileName, DWORD* pWidth, DWORD* pHeight, void** pData )
    {
    	HDC hMemDC;
    	HBITMAP hBitmap;
    	GdiplusStartupInput m_gdiplusStartupInput;
    	ULONG_PTR m_pGdiToken;
    
    	GdiplusStartup( &m_pGdiToken, &m_gdiplusStartupInput, NULL );
    	{
    		hMemDC = CreateCompatibleDC( NULL );
    
    		Image image( pFileName, FALSE );
    		*pWidth = image.GetWidth();
    		*pHeight = image.GetHeight();
    
    		BITMAPINFO bi;		
    		ZeroMemory( &bi, sizeof(BITMAPINFO) );
    
    		bi.bmiHeader.biSize		= sizeof(BITMAPINFOHEADER);
    		bi.bmiHeader.biBitCount		= 32;
    		bi.bmiHeader.biWidth		= *pWidth;
    		bi.bmiHeader.biHeight		= *pHeight;
    		bi.bmiHeader.biCompression	= BI_RGB;
    		bi.bmiHeader.biPlanes		= 1;
    
    		hBitmap = CreateDIBSection( hMemDC, &bi, DIB_RGB_COLORS,
    			pData, 0, 0 );
    		SelectObject( hMemDC, hBitmap );
    		RECT rect = { 0, 0, *pWidth, *pHeight };
    		FillRect( hMemDC, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH) );
    		Graphics graphics( hMemDC );
    		graphics.DrawImage( &image, 0, 0, *pWidth, *pHeight );
    	}
    	DeleteDC( hMemDC );
    	GdiplusShutdown( m_pGdiToken );
    	return hBitmap;
    }
  • 相关阅读:
    Spring容器启动前传——web应用
    三方依赖bean初始化导致项目启动失败问题
    一个静态内部类单例引发的思考
    依赖传递
    kafka
    设置旋转元素的基点位置
    keep-alive 的 Props && 钩子函数
    css处理文字: 单行居中 多行居左
    localStorage 存 取 删
    for循环中暂停,async await
  • 原文地址:https://www.cnblogs.com/LinuxHunter/p/1885842.html
Copyright © 2020-2023  润新知