以下是我的程序,但输出的图片在网页中显示是白的,没有任何东西。
请高手指教。#include "stdafx.h"
#include <atlimage.h>int _tmain(int argc, _TCHAR* argv[])
{
CImage img;
img.Create(256,256,32,CImage::createAlphaChannel);
HDC hdc = img.GetDC(); RECT rect = {10,10,200,200};
::SetTextColor(hdc,RGB(255,255,0));
::DrawEdge(hdc,&rect,EDGE_BUMP,BF_RECT);
::DrawText(hdc,"This is a test!",15,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER); img.ReleaseDC();
img.Save("d:\\temp\\temp.png"); return 0;
}
请高手指教。#include "stdafx.h"
#include <atlimage.h>int _tmain(int argc, _TCHAR* argv[])
{
CImage img;
img.Create(256,256,32,CImage::createAlphaChannel);
HDC hdc = img.GetDC(); RECT rect = {10,10,200,200};
::SetTextColor(hdc,RGB(255,255,0));
::DrawEdge(hdc,&rect,EDGE_BUMP,BF_RECT);
::DrawText(hdc,"This is a test!",15,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER); img.ReleaseDC();
img.Save("d:\\temp\\temp.png"); return 0;
}
SetTransparentColor
//#include "stdafx.h"
#include <windows.h>
#include <GdiPlus.h>using namespace Gdiplus;int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytes ImageCodecInfo* pImageCodecInfo = NULL; GetImageEncodersSize(&num, &size);
if(size == 0)
return -1; // Failure pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL)
return -1; // Failure GetImageEncoders(num, size, pImageCodecInfo); for(UINT j = 0; j < num; ++j)
{
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j; // Success
}
} free(pImageCodecInfo);
return -1; // Failure
}class GdiplusInit
{
public:
GdiplusInit()
{
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
}
~GdiplusInit()
{
GdiplusShutdown(gdiplusToken);
}
protected:
private:
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
};GdiplusInit init;
int _tmain(int argc, _TCHAR* argv[])
{ Bitmap bmp(256,256);
Graphics gp(&bmp); Pen pen(Color(128,255,0,0));
gp.DrawLine(&pen,Point(0,0),Point(256,256)); CLSID pngClsid;
GetEncoderClsid(L"image/png", &pngClsid);
bmp.Save(L"d:\\temp\\temp.png",&pngClsid);
return 0;
}