如果你真的想使用C++,你应该看看使用GDI +,这是标准的Windows/VS图形方式。这是一个稍微高一点的(友好的)api比旧的GDI api做图形可以追溯到(预)MFC天。您需要掌握设备上下文等基本知识,以了解如何从文件加载位图并将其显示在屏幕上。
CGI +允许使用LockBits方法以像素为单位轻松操作位图。它可以读取最常见的图像格式(BMP,JPG,PNG等)。
以下示例代码示出了一个典型的负载位图和读取一些像素类型码(它被逐字取自this msdn gdi+ article
#include <windows.h>
#include <gdiplus.h>
#include <stdio.h>
using namespace Gdiplus;
INT main() {
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
Bitmap* bitmap = new Bitmap(L"LockBitsTest1.bmp");
BitmapData* bitmapData = new BitmapData;
Rect rect(20, 30, 5, 3);
// Lock a 5x3 rectangular portion of the bitmap for reading.
bitmap->LockBits(
&rect,
ImageLockModeRead,
PixelFormat32bppARGB,
bitmapData);
printf("The stride is %d.\n\n", bitmapData->Stride);
// Display the hexadecimal value of each pixel in the 5x3 rectangle.
UINT* pixels = (UINT*)bitmapData->Scan0;
for(UINT row = 0; row < 3; ++row) {
for(UINT col = 0; col < 5; ++col)
printf("%x\n", pixels[row * bitmapData->Stride/4 + col]);
printf("- - - - - - - - - - \n");
}
bitmap->UnlockBits(bitmapData);
delete bitmapData;
delete bitmap;
GdiplusShutdown(gdiplusToken);
return 0;
}
至于拉线,绘制曲线等例程 - 这些都发现在图形对象中GDI +,它的主要对象,你的代码和屏幕之间坐镇。图形对象将被用来渲染使用Graphics.DrawImage以上的位图。
“Plain C++”不包含任何内容与图形一起工作。你必须选择一些图形库/工具包。 –
您可以直接将位图文件格式解析为您自己的像素数组:http://en.wikipedia.org/wiki/BMP_file_format或者您可以使用类似OpenCV的库(http://opencv.willowgarage.com/wiki/) – TJD
不幸的是,即使在Windows世界中,这也变得很复杂。有许多第三方图形库,以及与各种类型的位图一起工作的Windows API。但是,您可能想浏览像CodeProject.com这样的网站,以查看使用Windows GDI操纵位图的各种程序/函数的示例。或者看一下GDI + API(更好用一点)。 – Mordachai