带圆角的位图

时间:2014-11-28 21:52:11

标签: winapi bitmap region

    GetWindowRect(hWnd, &wnd);
    hdc = BeginPaint(hWnd, &ps);
    hdcMem = CreateCompatibleDC(hdc);

    for (int i = 0; i < n; ++i)
    {
        HRGN rgn = CreateRoundRectRgn(0, 0, CARD_WIDTH, CARD_HEIGHT, 7, 7);
        SetWindowRgn(cards[info[i].card], rgn, TRUE);
        oldBitmap = SelectObject(hdcMem, cards[info[i].card]);
        GetObject(cards[info[i].card], sizeof(bitmap), &bitmap);
        BitBlt(hdc, info[i].pos.x, info[i].pos.y, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY);
        SelectObject(hdcMem, oldBitmap);
    }

我对位图图片的切角有问题。

1 个答案:

答案 0 :(得分:1)

GetWindowRect(hWnd, &wnd);
        hdc = BeginPaint(hWnd, &ps);
        hdcMem = CreateCompatibleDC(hdc);
        for (int i = 0; i < n; ++i)
        {
            HRGN rgn = CreateRoundRectRgn(info[i].pos.x, info[i].pos.y, info[i].pos.x + CARD_WIDTH, info[i].pos.y + CARD_HEIGHT, 7, 7);
            SelectClipRgn(hdc, rgn);
            oldBitmap = SelectObject(hdcMem, cards[info[i].card]);
            GetObject(cards[info[i].card], sizeof(bitmap), &bitmap);
            BitBlt(hdc, info[i].pos.x, info[i].pos.y, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY);
            SelectObject(hdcMem, oldBitmap);
        }

感谢Jonathan Potter。