Windows 内存绘图导出RGB

Windows 内存绘图导出RGB

1,       MFC 创建内存绘图显示设备

               1) 

CDC MemDC;  
		CBitmap MemBitmap; 
		CRect rect;
		m_gl.GetClientRect(rect);
		CDC *pDc = m_gl.GetDC();
		MemDC.CreateCompatibleDC(pDc); 
		 
		MemBitmap.CreateCompatibleBitmap(pDc, rect.Width(), rect.Height());
	 
		 
		CBitmap *pOldBit = MemDC.SelectObject(&MemBitmap);

  2)获取内存数据,窗口兼容的CDC一般是32位深度,RGBA格式

     

               BITMAP bitmap;
		LONG size = ::GetObject(MemBitmap, sizeof(BITMAP),&bitmap);
		DWORD dwSize = bitmap.bmHeight * bitmap.bmWidthBytes;
		unsigned char * ptr = new unsigned char[dwSize];
		MemBitmap.GetBitmapBits(dwSize, ptr);

2, Win32 

1)

 HDC hDC = ::GetDC(m_windowWnd);
    HDC hDCMem;
    HBITMAP hBmpMem, hPreBmp;
    /* 创建双缓冲区 */
    // 创建与当前DC兼容的内存DC
    hDCMem = CreateCompatibleDC(hDC);
    // 创建一块指定大小的位图
//hBmpMem = ::CreateBitmap(iWidth, iHeight, 1, 32, pBmpData); hBmpMem = CreateCompatibleBitmap(hDC, 64, 64); // 将该位图选入到内存DC中,默认是全黑色的 hPreBmp = (HBITMAP)::SelectObject(hDCMem, hBmpMem);
2)

 
    HBITMAP hbmp = hBmpMem;


    if(!::GetObject(hbmp, sizeof(BITMAP), (LPBYTE)&bmptemp))
        return 0;


    BYTE imgSize = bmptemp.bmBitsPixel / 8; //兼容24bit和32bit位图
    BITMAPINFO bi = { 0 };
    bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
    bi.bmiHeader.biWidth = bmptemp.bmWidth;
    bi.bmiHeader.biHeight = bmptemp.bmHeight;
    bi.bmiHeader.biPlanes = 1;
    bi.bmiHeader.biBitCount = bmptemp.bmBitsPixel;
    bi.bmiHeader.biCompression = BI_RGB;
    bi.bmiHeader.biSizeImage = bmptemp.bmWidth * imgSize * bmptemp.bmHeight;
    bi.bmiHeader.biClrUsed = 0;
    bi.bmiHeader.biClrImportant = 0;
    // 获取位图数据
    BYTE* lpvBits = new BYTE[bi.bmiHeader.biSizeImage];
    ::ZeroMemory(lpvBits, bi.bmiHeader.biSizeImage);
if(!::GetDIBits(hDCMem, hBmpMem, 0, bmptemp.bmHeight, lpvBits, &bi, DIB_RGB_COLORS)) {
        delete[] lpvBits;
        lpvBits = NULL;
    }


 

3,GDI,以上两种方法背景默认黑色,可是设置填充掩码颜色,实现透明效果

<span style="background-color: rgb(255, 255, 255); font-family: Arial, Helvetica, sans-serif;"></span><pre name="code" class="html">Bitmap bmp(bitmap.bmWidth, bitmap.bmHeight, PixelFormat32bppARGB);
		Graphics GDIplusObj(&bmp);
		Color aa(200, 200, 200, 0);
		Color bb = aa;	Pen pen(aa, 3);
		// 	aa.MakeARGB(100, 255, 0, 0);
		SolidBrush brush(bb);
		SolidBrush brush2(Color(100,255, 0, 0));
		GDIplusObj.FillRectangle(&brush2, 100, 100, 100, 100);
Graphics GDIplusObj2(m_gl.GetDC()->GetSafeHdc()); 
GDIplusObj2.DrawImage(&bmp, Rect(0, 0, rect.Width(), rect.Height()));
//获取内存数据
//将Bitmap中的图像数据Buffer导出//用GDI的GetDIBits方法,用GDI+的LockBits方法


                
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值