c# code128条形码 文字居中

///
///显示可见条码文字 如果小于40 不显示文字
///
///图形
private void GetViewText(Bitmap p_Bitmap, string p_ViewText)
{
if (m_ValueFont == null)
return;
Graphics _Graphics = Graphics.FromImage(p_Bitmap);
SizeF _DrawSize = _Graphics.MeasureString(p_ViewText, m_ValueFont);
if (_DrawSize.Height > p_Bitmap.Height - 10 || _DrawSize.Width > p_Bitmap.Width)
{
_Graphics.Dispose(); return;
}
int _StarY = p_Bitmap.Height - (int)_DrawSize.Height;
_Graphics.FillRectangle(Brushes.White, new Rectangle(0, _StarY, p_Bitmap.Width, (int)_DrawSize.Height));
//在文字前面加上空格
_Graphics.DrawString(” “+p_ViewText, m_ValueFont, Brushes.Black, 0, _StarY);
}

你可能感兴趣的:(c#,优秀案例)