什么Windows函数可以写入像素的矩形
What Windows function writes a rectangle of pixels?
我一直在使用WriteConsoleOutput函数,它所做的就是在命令提示符中写入一个矩形字符。然而,对于使用像素操作而不是字符操作的程序,Windows函数是什么来编写像素矩形?功能类似于WriteConsoleOutput,从数组中获取信息并写入,但使用像素而不是字符。我不是指在图像编辑器中看到的线条或填充形状。我的意思是,就像存储在数组中的图像一样,其中的一个矩形块被写入屏幕。
图形代码是这样完成的:
#include <windows.h>
#include <stdint.h>
#include <iomanip>
#include <string>
#include <cstring>
const int width = 640;
const int height = 480;
uint32_t bitmapdata[width*height];
BITMAP bitmap = {0, width, height, width*4, 1, 32, bitmapdata};
BITMAPINFOHEADER bitmapinfoheader = {sizeof(BITMAPINFOHEADER), width, -height, 1, 32, BI_RGB, width*height*4, 3779, 3779, 0, 0};
BITMAPINFO bitmapinfo = {bitmapinfoheader, 0};
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int main(){
// Register the window class.
const char CLASS_NAME[] = "test2";
WNDCLASS wc = { };
wc.lpfnWndProc = WindowProc;
wc.hInstance = GetModuleHandle( 0 );
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// Create the window.
HWND hwnd = CreateWindowEx(
0, // Optional window styles.
CLASS_NAME, // Window class
"test", // Window text
WS_OVERLAPPEDWINDOW, // Window style
// Size and position
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, // Parent window
NULL, // Menu
GetModuleHandle( 0 ), // Instance handle
NULL // Additional application data
);
if (hwnd == NULL)
{
return -1;
}
ShowWindow(hwnd, 1);
MSG msg = { };
HDC screenhandle = GetDC(NULL);
HDC handle = GetDC(hwnd);
HDC screen = CreateCompatibleDC(handle);
HBITMAP bitmaphandle = CreateCompatibleBitmap(handle, width, height);
SelectObject(screen, bitmaphandle);
for(int i=0; i<width*height; i++){
bitmapdata[i] = i;
}
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
SetDIBits(screen, bitmaphandle, 0, height, bitmapdata, &bitmapinfo, 0);
BitBlt(handle, 0, 0, width, height, screen, 0, 0, SRCCOPY);
}
return 0;
return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
它确实从像素数组中写入一个像素矩形,特别是由32位像素值组成的位图数据。while(GetMessage(&msg,NULL,0,0(({TranslateMessage(&aamp;msg(;DispatchMessage(&ap;msg;(}循环由每帧运行的代码组成,WindowProc指定在DispatchMessage中的事件期间执行的内容。此示例代码编写了一个640×480的测试矩形,其中像素分别为编号颜色。
相关文章:
- 如何在不产生任何垃圾的情况下获得C中的像素
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- 如何在24位SDL_Surface上设置像素的颜色
- 如何从SDL_Surface获取特定像素的颜色
- 如何将CMSampleBufferRef/CIImage/UIImage转换为像素,例如uint8_t[]
- 在C++中查找像素 RGB 数据的最快方法是什么?
- 是否可以从 OpenGL 缓冲区获取原始大小的像素?
- 选择基于另一个垫子的非零像素的cv::Mat的一部分?
- 如何使用 sdl2 快速绘制像素网格?
- 如何在C++中进行像素操作? - Linux
- 他们如何将红外锁定像素转换为镜头前方 1m 的正常平面上的位置
- 访问随机图像像素的快速方法,最多一次
- OpenCV 像素访问点与 at() - 不同的值
- 在Windows上获取OpenGL点大小(以像素为单位)?
- 使用视觉C++设置"Windows Form Application"中的像素值
- 如何使用 Windows API 获取像素格式布局
- 如何在windows控制台中为特定像素着色
- 如何使用 DrawText 查找在 Windows 中呈现的文本的确切像素高度
- 创建后如何使用Windows API(C++)设置窗口像素的颜色?
- C# 或 C++ - 概述 Windows 图形的良好资源 - 2D,直接绘制像素