渲染缓冲上Windows屏幕 [英] Render Buffer on Screen in Windows

查看:152
本文介绍了渲染缓冲上Windows屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一种方式呈现一个字符缓冲区到一个窗口的内容区域。这只是假,但为了证明我真正想要做的:

I'm searching for a way rendering a char buffer onto the content-area of a window. This is just pseudo but intended to demonstrate what I actually want to do:

char buffer[300][200][3];    // 300px x 200px x RGB bytes
// ... render stuff into buffer
FancyWindowsFunctionToRenderBufferOnWindow(my_hwnd, buffer, 300, 200, offset_x, offset_y);

有没有办法做同样的事情?

Is there a way to do something similar?

推荐答案

我认为你需要创建一个设备无关的位图(DIB)。如果你已经有了一个像素阵列是准备一个应用程序窗口上放,你可能需要将整个阵列复制到由CreateDIBSection API分配的缓冲区并调用的BitBlt到DIB传递给窗口。这是我知道的显示像素仅为阵列作为Win32平台上的电脑屏幕上的可见图像的唯一途径,这是非常复杂的,很难理解。

I think you need to create a device independent bitmap (DIB). If you already have an array of pixels that is ready to be put on an application window, you may need to copy the whole array to the buffer allocated by the CreateDIBSection API and call BitBlt to transfer the DIB to the window. This is the only way I know to show a mere array of pixels as a visible picture on the computer screen on Win32 platform and it is highly complicated and difficult to understand.

下面是我用你想要做什么,采取测试的东西类似的步骤:

Here are the steps I used to take to test things similar to what you want to do:

创建DIB:

BITMAPINFO bmi;
memset(&bmi, 0, sizeof(bmi));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = /* Width of your image buffer */
bmi.bmiHeader.biHeight = - /* Height of your image buffer */
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;

HDC hDesktopDC = GetDC(GetDesktopWindow());
HBITMAP hDib = CreateDIBSection(hDesktopDC, &bmi, DIB_RGB_COLORS, (void **)&buffer, 0, 0);
if (buffer == NULL) { /* ERROR */ }
HDC hDibDC = CreateCompatibleDC(hDesktopDC);
HGDIOBJ hOldObj = SelectObject(hDibDC, hDib);

/* Copy your array of pixels to buffer allocated above. */

ReleaseDC(GetDesktopWindow(), hDesktopDC);

实施WM_PAINT事件处理程序(HWND的变量包含下面的窗口办理):

Implementing WM_PAINT event handler (the hWnd variable holds the window handle below):

case WM_PAINT:
    PAINTSTRUCT paint;
    HDC hWndDc = BeginPaint(hWnd, &paint);
    BitBlt(hWndDC, 0, 0, /* Width of DIB */, /* Height of DIB */,
           /* HDC of DIB (hDibDC in the above) */, 0, 0, SRCCOPY);
    EndPaint(hWnd, &paint);
    break;

我真的不希望上述code段将直接帮助你。如果你有决心使用GDI功能,如那些在上面的代码片段,我建议你仔细阅读MSDN上他们的API文档。因为它是非常棘手的正确释放或删除的DC或GDI对象获得使用API​​中。

I don't really expect the above code snippets would directly help you. If you are determined to use GDI functions like ones in the above snippets, I recommend you to read very carefully their API documents on MSDN. Because it is very tricky to properly release or delete DCs or GDI objects acquired during using the APIs.

这篇关于渲染缓冲上Windows屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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