如何镜像 HBITMAP

how to mirror a HBITMAP

如何水平翻转 HBITMAP?作为一个选项,我想从 BITMAP 获取一组颜色并将它们写入另一个 BITMAP,但不知何故它太忙了。是否有内置函数或其他选项来执行此操作?

您可以将 StretchBlt 与负维度一起使用,如下所示:

HBITMAP FlipBitmapHorizontally(HBITMAP hbm) {
    BITMAP bm;
    GetObject(hbm, sizeof(BITMAP), &bm);
    int wd = bm.bmWidth;
    int hgt = bm.bmHeight;

    HDC hdcScr = GetDC(NULL);
    HDC hdcFlipped = CreateCompatibleDC(hdcScr);
    HBITMAP hbmFlipped = CreateCompatibleBitmap(hdcScr, wd, hgt);
    HGDIOBJ oldFlipped = SelectObject(hdcFlipped, hbmFlipped);
    HDC hdcSrc = CreateCompatibleDC(hdcScr);
    HGDIOBJ oldSrc = SelectObject(hdcSrc, hbm);

    StretchBlt(hdcFlipped, wd, 0, -wd, hgt, hdcSrc, 0, 0, wd, hgt, SRCCOPY);

    SelectObject(hdcSrc, oldSrc);
    DeleteDC(hdcSrc);
    SelectObject(hdcFlipped, oldFlipped);
    DeleteDC(hdcFlipped);
    ReleaseDC(NULL, hdcScr);

    return hbmFlipped;
}