BitBlt 问题 GDI [英] BitBlt Problem GDI

查看:35
本文介绍了BitBlt 问题 GDI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此程序中使用 BitBlt 时遇到问题.您调整窗口大小,椭圆也随之调整大小.当然,用普通的 hdc 方法,它是断断续续的和闪烁的.我尝试了 BitBlt 方法,但这也不起作用(可能是因为我做错了).有人可以解决我的错误吗?谢谢

I am having trouble with using BitBlt in this program. You resize the window and the ellipse resizes with it. Of course, with the normal hdc method, It is choppy and flickery. I tried the BitBlt method, but that doesn't work either (probably because im doing it wrong). Can someone fix my what Im donig wrong? thanx

    bool sizing; //global   
case WM_PAINT:
    {
        RECT rect;
        GetClientRect(hwnd, &rect);
        hdc = BeginPaint(hwnd, &ps);
        mem = CreateCompatibleDC(hdc);
        SelectObject(mem, GetStockObject(HOLLOW_BRUSH));
        if(sizing)
        {
        Ellipse(mem,rect.left, rect.top, rect.right, rect.bottom);
        }
    BitBlt(hdc, rect.left, rect.top, rect.left - rect.right, rect.top -rect.bottom , mem, rect.left, rect.top, SRCCOPY);
        DeleteDC(mem);
        EndPaint(hwnd, &ps);
        break;
    }
    case WM_SIZE:
        sizing = true;
        break;

推荐答案

看起来您正在尝试绘制基于内存的位图,然后将其 bitblt 到屏幕上,以避免闪烁?

It looks like you're trying to draw to a memory-based bitmap, and then bitblt that to the screen, to avoid flicker?

这里的第一个问题是处理闪烁:首先,您需要像 Hans 指出的那样覆盖 WM_ERASEBKGND - 否则 Windows 将使用任何窗口画笔(来自 RegisterClass)擦除背景,而这种擦除是闪烁的常见原因.

First issue here is dealing with flicker: first you need to override WM_ERASEBKGND as Hans points out - otherwise Windows will erase the background with whatever the window brush is (from RegisterClass), and that erasing is the usual cause of flicker.

这里的下一个问题是您使用的是空"DC:CreateCompatibleDC 为您提供 DC - 这只是一个绘图上下文 - 但该上下文包含一个 1 x 1 像素的位图.要在屏幕外绘制,您需要一个 DC 一个位图.一定要花时间阅读 CreateCompatible 的 MSDN 页面 - 它指出了这一点确切的问题.

The next problem here is that you're using an 'empty' DC: CreateCompatibleDC gives you a DC - which is just a drawing context - but the context contains a 1 pixel by 1 pixel bitmap. To draw offscreen, you need a DC and a bitmap. Do take time to read the MSDN page for CreateCompatible - it calls out this exact issue.

如果您对此不熟悉,请将位图视为您绘制的实际画布 - DC 只是进行绘制的支持结构.就您的代码而言,您已经设置了画架和画笔 - 但您没有在任何东西上作画.

If you're new to this, think of a bitmap as the actual canvas that you draw on - the DC is just the support structure to do that drawing. As your code stands, you've got the easel and paint brushes set up - but you're not painting on anything.

这里通常的方法是:

  • CreateCompatibleDC 以创建 DC
  • CreateCompatibleBitmap 创建您实际绘制的位图
  • 选择将您的新位图对象放入内存 DC
  • 绘制到内存 DC - 它在您选择的位图上绘制
  • BitBlt 从内存 DC(即你的位图,被选入其中)到 WM_PAINT 中的一个
  • 清理:SelectObject 将原始位图放回内存 DC,并删除位图和 DC.

这篇关于BitBlt 问题 GDI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆