---
title: "GetBitmapBits 以及 SetBitmapBits的用法"
author: "hzdiy"
date: "2010-09-30T23:28:41Z"
tags: []
categories: ["编程语言"]
slug: "getbitmapbits-setbitmapbits"
draft: false
lastmod: "2010-09-30T23:28:41Z"
id: 776359
url: "https://hzdiy.iteye.com/blog/776359"
---

HBITMAP hCaptureBitmap = CopyScreenToBitmap(0, 1024,0, 768);
CBitmap*   pBmp   =   CBitmap::FromHandle(hCaptureBitmap); 
int Count;
BITMAP bm;     
pBmp->GetObject(sizeof(bm),&bm);
Count = bm.bmWidthBytes * bm.bmHeight; //得到buf大小
BYTE *b=new BYTE;
pBmp->GetBitmapBits(Count,b);

HDC hdc=::GetDC(m_hWnd);//
HDC mdc=CreateCompatibleDC(hdc);
HBITMAP MyBit=CreateCompatibleBitmap(hdc,1024,768);
SetBitmapBits(MyBit,Count,b);
SelectObject(mdc,MyBit);
BitBlt(hdc,0,0,1024,768,mdc,0,0,SRCCOPY);
::ReleaseDC(m_hWnd,hdc);
DeleteObject((HGDIOBJ)mdc); 
delete  b;