19,464
社区成员
发帖
与我相关
我的任务
分享int imX = 100; //这里设定了固定的值 你需要自己计算出这两个值
int imY = 100;
Bitmap mImg( imX, imY ); //建立一个一定你要求大小的图
Graphics* g = Graphics::FromImage( &mImg ); //同图像获得绘图句柄,说白了就是找一个专属于这个图像的画图工具
g->SetPageUnit( UnitPixel ); //这句可以不设定也可以的 只是提醒一下可能会有单位问题
Font myFont( L"新宋体", 20, 0, UnitPixel );
SolidBrush blackBrush( Color( 255, 0, 0, 255 ) );
PointF orL; //初始绘图位置,你如果要求图像边缘紧贴文字这里需要设定为(0,0);
orL.X = 10;
orL.Y = 10;
g->DrawString( L"This is a text!", 7, &myFont, orL, &blackBrush );
CLSID pngClsid;
GetEncoderClsid( L"image/png", &pngClsid ); //取得PNG的编码ID,函数到http://msdn.microsoft.com/en-us/library/ms533843(VS.85).aspx去自己考
mImg.Save(L"N.png", &pngClsid, NULL); //保存为PNG