控制台窗口中的C ++像素 [英] C++ Pixels In Console Window
问题描述
在C ++中使用Code :: Blocks v10.05,如何在控制台屏幕上绘制单个像素?这是很容易,还是会更容易绘制一个矩形?我如何着色?对不起,我只是不能得到任何代码从SOF,HF,甚至cplusplus.com工作。这是一个超级马里奥世界人物在屏幕上。游戏我认为是16位,是为SNES系统。 C :: B说我需要SDK for C :: B。它说afxwin.h不存在。下载也许?这是我想要做的:
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? 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? This is what I'm trying to make:
推荐答案
这取决于您的操作系统。我假设您在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 ++像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!