简体   繁体   English

位图如何在 window 上绘制像素?

[英]How does bitmaps draw pixel on window?

So I followed a few tutorials on how to draw on window using windows.h library, the part of the tutorial that I don't really understand is the bitmap part.因此,我遵循了一些关于如何使用 windows.h 库在 window 上绘图的教程,教程中我不太了解的部分是 bitmap 部分。 They used createbitmap() and StrechBit() functions to draw on window.他们使用 createbitmap() 和 StrechBit() 函数在 window 上绘图。 Do window references bitmap to draw pixels on the screen accordingly and bitmap is basically a chunk of memory large enough to store pixel's position and color value. Do window references bitmap to draw pixels on the screen accordingly and bitmap is basically a chunk of memory large enough to store pixel's position and color value. If so, does bitmap automatically generate every time you created a window, because it seems that you don't really need to declare bitmap or use createbitmap() functions to type word on the window you created, you only need to create bitmap when you want to draw a custom pixel. If so, does bitmap automatically generate every time you created a window, because it seems that you don't really need to declare bitmap or use createbitmap() functions to type word on the window you created, you only need to create bitmap when you想要绘制一个自定义像素。

A window will receive the WM_PAINT message when it needs to be painted. window 在需要绘制时会收到WM_PAINT消息。 This can happen because InvalidateRect was called, the window was resized etc.这可能是因为调用了InvalidateRect 、调整了 window 的大小等。

Where the pixels are stored ("in" the HWND) is an implementation detail you don't have to worry about.像素的存储位置(“在”HWND 中)是您不必担心的实现细节。 On some versions/configurations the GDI functions are hardware accelerated and the result might be stored directly in the GPU, in others everything might be implemented in software and run on the CPU.在某些版本/配置中,GDI 功能是硬件加速的,结果可能直接存储在 GPU 中,而在其他版本/配置中,一切都可能在软件中实现并在 CPU 上运行。 When using a layered window I'm guessing everything older than Vista will use an internal bitmap to store the pixels.当使用分层 window 时,我猜测比 Vista 更早的所有东西都将使用内部 bitmap 来存储像素。

GDI/GDI+ is the classic way to draw windows. GDI/GDI+是绘制windows的经典方式。 If you need per-pixel alpha transparency you would draw to a bitmap and call UpdateLayeredWindow , otherwise you would just draw using any GDI function you want in WM_PAINT .如果您需要每像素 alpha 透明度,您将绘制到 bitmap 并调用UpdateLayeredWindow ,否则您只需在WM_PAINT中使用您想要的任何 GDI function 进行绘制。 This might include drawing one or several bitmaps, text, and lines/curves directly to the HWNDs HDC.这可能包括将一个或多个位图、文本和线条/曲线直接绘制到 HWNDs HDC。 As this can cause flicker in certain cases (if any area is drawn to more than once in one paint cycle), so people might draw to their own bitmap first and then BitBlt this bitmap to the window, this is called double-buffering.由于这在某些情况下会导致闪烁(如果任何区域在一个绘制周期中被多次绘制),因此人们可能会先绘制到自己的 bitmap,然后将这个BitBlt绘制到 Z05B8C74CBD96FBF2DE4C1A352702,这被称为双 FFF4C1A352702。

The new way to draw is Direct2d/ DirectComposition .新的绘制方法是 Direct2d/ DirectComposition

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM