wince(2) 位图的使用

回忆位图画刷的使用步骤:

````````` 
 PAINTSTRUCT ps;
  RECT rect;
GetClientRect(hwnd,&rect);
HDC hdc = BeginPaint(hwnd,&ps);
HBitMap hmp = LoadBitMap(g_hInst,MAKEINTRESOURCE(IDB_BITMAP1));
BRUSH brush = CreatePatternBrush(hmp);
HGDIOBJ oldbrush = SelectObject(hdc,brush);// save
Ellipse(hdc,10,10,200,200);
SelectObject(hdc,oldbrush);
DeleteObject(hmp);//clear the rc used
DeleteObject(brush);//clear DC
EndPaint(hwnd,&ps);
  

 

  

位图使用操作的步骤:

  1.创建位图句柄;

  2.加载位图对象(3种方法,LoadBitMap,设备相关CreateBitMap,设备无关SHLoadDIBitmap);

  3.创建“内存设备环境”(memory device context,使用CreateCompatibleDC),

  选入设备对象是SelectObject,不必要保存的,

 HGIDOBJ holdmem = SelectObject(hmem,hbitmap)将位图选入设备环境··(3种方法,BitBlt,StretchBlt,TransparentBlt==TransparentImage

  4.使用绘图函数进行图形的绘制

  5.删除位图句柄

          

View Code
HBITMAP CopyBitmap( HBITMAP hbm) {
    HDC hdcSrc = CreateCompatibleDC(NULL);
    HDC hdcDst = CreateCompatibleDC(NULL);
    HBITMAP hbmOld, hbmOld2, hbmNew;
    BITMAP bm;
    GetObject(hbm, sizeof(bm), &bm);
    hbmOld = SelectObject(hdcSrc, hbm);
    hbmNew = CreateBitmap( bm.bmWidth, bm.bmHeight, bm.bmPlanes,
bm.bmBitsPixel,
            NULL);
    hbmOld2 = SelectObject(hdcDst, hbmNew);
    BitBlt(hdcDst, 0, 0, bm.bmWidth, bm.bmHeight, hdcSrc, 0, 0, SRCCOPY);
    SelectObject(hdcSrc, hbmOld);
    DeleteDC(hdcSrc);
    DeleteDC(hdcDst);
    return hbmNew;
}

 

posted on 2013-03-08 22:02  イケメンおっさん_汪汪  阅读(204)  评论(0编辑  收藏  举报

导航