废话
用过不知多少开源图像库,其实似乎无例外的都是几个图像解码库zlib、libpng、libjpeg的封装。够了,基本可以解决所有图像问题。GdiPlus这种要死不活的东西,拜微软所赐,偶今天才有空去瞅瞅。玩一下吧,不想为了写几行代码去整个开源的解码库。别了,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);
}