本文整理汇总了C#中IFont.DrawString方法的典型用法代码示例。如果您正苦于以下问题:C# IFont.DrawString方法的具体用法?C# IFont.DrawString怎么用?C# IFont.DrawString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFont
的用法示例。
在下文中一共展示了IFont.DrawString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateBitmapFromString
public static Bitmap CreateBitmapFromString( RuntimeFont font, Bitmap pngBitmap, string testString, int startX, int startY, IFont comparisonFont=null )
{
// Get the character positions.
FontLayout.CharacterLayout[] layouts = FontLayout.LayoutCharacters( font, testString, 0, 0 );
// Draw the character.
int extraLineSpacing = 5;
int width = 1;
int height = 1;
if ( layouts.Length > 0 )
{
width = layouts[ layouts.Length - 1 ].XOffset + font.LineHeight * 2;
height = layouts[ layouts.Length - 1 ].YOffset + font.LineHeight;
}
if ( comparisonFont != null )
{
height += font.LineHeight + extraLineSpacing;
}
Color textColor = Color.White;
Bitmap bitmap = new Bitmap( width, height, PixelFormat.Format32bppArgb );
using ( Graphics g = Graphics.FromImage( bitmap ) )
{
g.Clear( Color.Transparent );
foreach ( FontLayout.CharacterLayout layout in layouts )
{
int sfi = layout.SudoFontIndex;
Rectangle srcRect = new Rectangle( font.Characters[sfi].PackedX, font.Characters[sfi].PackedY, font.Characters[sfi].PackedWidth, font.Characters[sfi].PackedHeight );
Rectangle destRect = new Rectangle( layout.XOffset, layout.YOffset, srcRect.Width, srcRect.Height );
g.DrawImage( pngBitmap, destRect, srcRect, GraphicsUnit.Pixel );
}
int curY = startY + font.LineHeight + extraLineSpacing;
if ( comparisonFont != null )
{
comparisonFont.DrawString( g, testString, new SolidBrush( textColor ), new Point( 0, curY ) );
curY += font.LineHeight + extraLineSpacing;
}
}
return bitmap;
}