C++ 如何设置像素的颜色?

来源:百度知道 编辑:UC知道 时间:2024/04/28 20:40:18
C++里面如何设置像素的颜色?
最好写一个简单的例子!
Win32命令行窗口

setpixel.

1、 获取屏幕DC

HDC hDC = ::GetDC(NULL); //获取屏幕DC
2、 获取当前鼠标位置像素值

CPoint pt;
GetCursorPos(&pt); //得到当前鼠标所在位置
COLORREF clr = ::GetPixel(hDC, pt.x, pt.y); //获取当前鼠标点像素值
3、 分解出像素点中的红、绿、蓝颜色值

CString ClrText;
ClrText.Format("%d",GetRValue(clr)); //分解出红色值
ClrText.Format("%d",GetGValue(clr)); //分解出绿色值
ClrText.Format("%d",GetBValue(clr)); //分解出蓝色值
::ReleaseDC(NULL, hDC); //释放屏幕DC

话问得有问题,GDI? SDL? OGL? DX?

Recently, I want to make some parts of C++ output with colors, but I don't have any idea in fact. So that I try to search with baidu.com, and find that SetConsoleTextAttribute can help me. Following is some descriptions of the API.

SetConsoleTextAttribute Function

The SetConsoleTextAttribute function sets the attributes of characters written to the console screen buffer by the WriteFile or WriteConsole function, or echoed by