本文主要为广大网友提供“VC++ GDI+编程的字体和文本绘制”,希望对需要VC++ GDI+编程的字体和文本绘制网友有所帮助,学习一下!
FontFamily fontFamily(L"幼圆"); // 定义"幼圆"字样 |
Font font(&fontFamily, 12, FontStyleRegular, UnitPoint); |
Font( HDC hdc, const LOGFONTW* logfont) |
DrawString( const WCHAR* string, INT length, const Font* font, const RectF& layoutRect, const StringFormat* stringFormat, const Brush* brush ); DrawString( const WCHAR* string, INT length, const Font* font, const PointF& origin, const Brush* brush ); DrawString( const WCHAR* string, INT length, const Font* font, const PointF& origin, const StringFormat* stringFormat, const Brush* brush); |
Graphics graphics( pDC->m_hDC ); FontFamily fontFamily(L"幼圆"); Font font(&fontFamily, 20, FontStyleRegular, UnitPoint); PointF pointF(30, 10); Image image(L"image.jpg"); TextureBrush tBrush(&image); LinearGradientBrush linGrBrush( Point(30, 50), Point(100, 50), Color(255, 255, 0, 0), Color(255, 0, 0, 255)); WCHAR string[256]; wcscpy(string, L"欢迎使用GDI+!"); graphics.DrawString(string, (INT)wcslen(string), &font, pointF, &tBrush); pointF.Y += 50; graphics.DrawString(string, (INT)wcslen(string), &font, pointF, &linGrBrush); |
Graphics graphics( pDC->m_hDC ); FontFamily fontFamily(L"楷体_GB2312"); Font font(&fontFamily, 30, FontStyleRegular, UnitPixel); SolidBrush solidBrush(Color(255, 0, 0, 255)); WCHAR string1[] = L"没有任何优化处理"; WCHAR string2[] = L"字体优化,但边不作平滑处理"; WCHAR string3[] = L"消除走样,且边作平滑处理"; graphics.SetTextRenderingHint(TextRenderingHintSingleBitPerPixel); graphics.DrawString( string1, (INT)wcslen(string1), &font, PointF(10, 10), &solidBrush); graphics.SetTextRenderingHint(TextRenderingHintSingleBitPerPixelGridFit); graphics.DrawString( string2, (INT)wcslen(string2), &font, PointF(10, 50), &solidBrush); graphics.SetTextRenderingHint(TextRenderingHintAntiAliasGridFit); graphics.DrawString( string3, (INT)wcslen(string3), &font, PointF(10, 90), &solidBrush); |
Status SetAlignment( StringAlignment align); Status SetLineAlignment( StringAlignment align); |
Status SetFormatFlags( INT flags ); |
Graphics graphics( pDC->m_hDC ); SolidBrush solidBrush(Color::Blue); FontFamily fontFamily(L"楷体_GB2312"); Font font(&fontFamily, 16, FontStyleRegular, UnitPoint); StringFormat stringFormat; stringFormat.SetFormatFlags( StringFormatFlagsDirectionRightToLeft | StringFormatFlagsDirectionVertical | StringFormatFlagsNoFitBlackBox); stringFormat.SetAlignment(StringAlignmentCenter); WCHAR string[] = L"这些文字是垂直居中且是从右到左的阅读次序, 它们是通过 \ SetFormatFlags和SetAlignment来设置的!"; graphics.DrawString( string, (INT)wcslen(string), &font, RectF(30, 30, 150, 200), &stringFormat, &solidBrush); |