如果你真的想使用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