廢話
用過不知多少開源圖像庫,其實(shí)似乎無例外的都是幾個(gè)圖像解碼庫zlib、libpng、libjpeg的封裝。夠了,基本可以解決所有圖像問題。GdiPlus這種要死不活的東西,拜微軟所賜,偶今天才有空去瞅瞅。玩一下吧,不想為了寫幾行代碼去整個(gè)開源的解碼庫。別了,zlib;別了,libpng;別了,skia;別了,freeimage;別了,cximage;別了,devil。別了,opensource。
source
MSDN About GDI+
http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx
Getting Started
http://msdn.microsoft.com/en-us/library/ms533807(v=VS.85).aspx
Image Class
http://msdn.microsoft.com/en-us/library/ms534462
Use
Note the call to GdiplusStartup in the WinMain function. The first parameter of the GdiplusStartup function is the address of a ULONG_PTR. GdiplusStartup fills that variable with a token that is later passed to the GdiplusShutdown function. The second parameter of the GdiplusStartup function is the address of a GdiplusStartupInput structure. The preceding code relies on the default GdiplusStartupInput constructor to set the structure members appropriately.
1.引用
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")
2.初始化與銷毀
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
// Initialize GDI+.
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);// Shutdown
GdiplusShutdown(gdiplusToken);
3.畫
VOID OnPaint(HDC hdc)
{
Graphics graphics(hdc);
Pen pen(Color(255, 0, 0, 255));
graphics.DrawLine(&pen, 0, 0, 200, 100);
}