Visual C++位图操作(1)
生活随笔
收集整理的這篇文章主要介紹了
Visual C++位图操作(1)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
?
一.BitBlt
將一幅位圖從一個設備場景復制到另一個,即復制像素,前面參數(shù)為目標,后者為源
case WM_PAINT:hdcClient = BeginPaint (hwnd, &ps) ;hdcWindow = GetWindowDC (hwnd) ;for (y = 0 ; y < cyClient ; y += cySource)for (x = 0 ; x < cxClient ; x += cxSource){BitBlt (hdcClient, x, y, cxSource, cySource,hdcWindow, 0, 0, SRCCOPY) ;}ReleaseDC (hwnd, hdcWindow) ;EndPaint (hwnd, &ps) ;return 0 ;二.拉伸位圖(會使圖片不清晰)
使用StretchBlt函數(shù),比BitBlt多了兩個參數(shù)
case WM_PAINT:hdcClient = BeginPaint (hwnd, &ps) ;hdcWindow = GetWindowDC (hwnd) ;StretchBlt (hdcClient, 0, 0, cxClient, cyClient,hdcWindow, 0, 0, cxSource, cySource, MERGECOPY) ;ReleaseDC (hwnd, hdcWindow) ;EndPaint (hwnd, &ps) ;return 0 ;三.創(chuàng)建位圖
3.1
hBitmap = CreateCompatibleBitmap (hdc, cx, cy) ; //此函數(shù)建立了一個與設備兼容的位圖 hBitmap CreateBitmapIndirect (&bitmap) ; //通過結構體創(chuàng)建3.2用位圖創(chuàng)建文字,用0和1表示,相當于畫像素點的意思.
填充BITMAP的bmBits字段
static BITMAP bitmap = { 0, 8, 8, 2, 1, 1 } ;static BYTE bits [8][2]={ 0xFF, 0, 0x0C, 0, 0x0C, 0, 0x0C, 0,0xFF, 0, 0xC0, 0, 0xC0, 0, 0xC0, 0 } ;static HBITMAP hBitmap ;static int cxClient, cyClient, cxSource, cySource ;HDC hdc, hdcMem ;int x, y ;PAINTSTRUCT ps ;switch (message){case WM_CREATE:bitmap.bmBits = bits ;hBitmap = CreateBitmapIndirect (&bitmap) ;cxSource = bitmap.bmWidth ;cySource = bitmap.bmHeight ;return 0 ;3.3使用位圖創(chuàng)建筆刷
hBitmap = LoadBitmap (hInstance, TEXT ("Bricks")); hBrush = CreatePatternBrush (hBitmap); DeleteObject (hBitmap);3.4在位圖中繪圖
用CreateCompatibleBitmap 創(chuàng)建一幅與設備兼容有關位圖,然后選擇位圖,SelectObject (hdcMem, hBitmap)
hdc = GetDC (hwnd) ; hdcMem = CreateCompatibleDC (hdc) ; GetTextExtentPoint32 (hdc, szText, lstrlen (szText), &size); cxBitmap = size.cx ; cyBitmap = size.cy; hBitmap = CreateCompatibleBitmap (hdc, cxBitmap, cyBitmap); ReleaseDC (hwnd, hdc) ; SelectObject (hdcMem, hBitmap) ; TextOut (hdcMem, 0, 0, szText, lstrlen (szText));創(chuàng)建好以后就可以同上方法用BitBlt或者StretchBlt方法操作像素了
四.菜單插入位圖
hBitmap = StretchBitmap (LoadBitmap (hInstance, TEXT ("BitmapFont"))) ; AppendMenu (hMenu, MF_BITMAP | MF_POPUP, (int) hMenuPopup,(PTSTR) (LONG) hBitmap) ;轉載于:https://www.cnblogs.com/Clingingboy/archive/2011/05/26/2059243.html
總結
以上是生活随笔為你收集整理的Visual C++位图操作(1)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 纯CSS实现iframe高度自适应,完美
- 下一篇: 301重定向!!