C++ Pixels In Console Window(控制台窗口中的 C++ 像素)
问题描述
在使用 Code::Blocks v10.05 的 C++ 中,如何在控制台屏幕上绘制单个像素?这很容易吗,还是只画一个矩形会更容易?如何给它上色?
In C++ using Code::Blocks v10.05, how do I draw a single pixel on the console screen? Is this easy at all, or would it be easier to just draw a rectangle? How do I color it?
很抱歉,我无法从 SOF、HF 甚至 cplusplus.com 获取任何代码来工作.这是屏幕上的超级马里奥世界人物.我认为是16位的游戏,适用于SNES系统.C::B 说我需要 C::B 的 SDK.它说afxwin.h";不存在.可以下载吗?
I'm sorry, but I just can't get any code from SOF, HF, or even cplusplus.com to work. This is for a Super Mario World figure on the screen. The game I think is 16-bit, and is for the SNES system. C::B says I need SDK for C::B. It says "afxwin.h" doesn't exist. Download maybe?
这就是我想要做的:
推荐答案
这取决于你的操作系统.我想你是在 Windows 平台上编程,因此你可以使用 SetPixel 但你必须使用"windows.h" 获取控制台句柄,这里以绘制 cos() 函数为例:
It depends on your OS. I suppose you are programming in a Windows platform, therefore you can use SetPixel but you have to use "windows.h" to get a console handle, so here an example for drawing the cos() function:
#include<windows.h>
#include<iostream>
#include <cmath>
using namespace std;
#define PI 3.14
int main()
{
//Get a console handle
HWND myconsole = GetConsoleWindow();
//Get a handle to device context
HDC mydc = GetDC(myconsole);
int pixel =0;
//Choose any color
COLORREF COLOR= RGB(255,255,255);
//Draw pixels
for(double i = 0; i < PI * 4; i += 0.05)
{
SetPixel(mydc,pixel,(int)(50+25*cos(i)),COLOR);
pixel+=1;
}
ReleaseDC(myconsole, mydc);
cin.ignore();
return 0;
}
您还可以使用其他一些库,例如:conio.h allegro.h sdl 等.
You can also use some others libraries like: conio.h allegro.h sdl, etc.
这篇关于控制台窗口中的 C++ 像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:控制台窗口中的 C++ 像素


- 如何对自定义类的向量使用std::find()? 2022-11-07
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 近似搜索的工作原理 2021-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 从python回调到c++的选项 2022-11-16
- C++ 协变模板 2021-01-01
- 静态初始化顺序失败 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01