比如我有一串数字 235323.32
现在我把它们全部画到一张图片上,我在网上考了这份代码string _FontName = "方正魏碑简体";
int _FontSize = 12;
string _ShowName ="32656.32";
Bitmap objBitmap = null;
Graphics g = null; Font stringFont = new Font(_FontName, _FontSize, FontStyle.Bold);
StringFormat stringFormat = new StringFormat();
stringFormat.FormatFlags = StringFormatFlags.NoWrap;
try
{
objBitmap = new Bitmap(1, 1);
g = Graphics.FromImage(objBitmap);
SizeF stringSize = g.MeasureString(_ShowName, stringFont);
int nWidth = (int)stringSize.Width;
int nHeight = (int)stringSize.Height;
g.Dispose();
objBitmap.Dispose(); objBitmap = new Bitmap(nWidth, nHeight);
g = Graphics.FromImage(objBitmap);
g.FillRectangle(new SolidBrush(Color.Green), new Rectangle(0, 0, nWidth, nHeight));
g.TextRenderingHint = TextRenderingHint.AntiAlias;
g.DrawString(_ShowName, stringFont, new SolidBrush(Color.Red), new PointF(0, 0), stringFormat);
objBitmap.Save(Response.OutputStream, ImageFormat.Gif);
}
catch (Exception ee)
{
Response.Write(ee.ToString());
}
finally
{
if (null != g) g.Dispose();
if (null != objBitmap) objBitmap.Dispose();
Response.End();
}
生成的图片上字体都是一并齐,我想要这样一个效果,比如其中的某个数字网上提一点,另外一个数字又往下一点,这下上下参差不齐,拜托大家帮帮忙
现在我把它们全部画到一张图片上,我在网上考了这份代码string _FontName = "方正魏碑简体";
int _FontSize = 12;
string _ShowName ="32656.32";
Bitmap objBitmap = null;
Graphics g = null; Font stringFont = new Font(_FontName, _FontSize, FontStyle.Bold);
StringFormat stringFormat = new StringFormat();
stringFormat.FormatFlags = StringFormatFlags.NoWrap;
try
{
objBitmap = new Bitmap(1, 1);
g = Graphics.FromImage(objBitmap);
SizeF stringSize = g.MeasureString(_ShowName, stringFont);
int nWidth = (int)stringSize.Width;
int nHeight = (int)stringSize.Height;
g.Dispose();
objBitmap.Dispose(); objBitmap = new Bitmap(nWidth, nHeight);
g = Graphics.FromImage(objBitmap);
g.FillRectangle(new SolidBrush(Color.Green), new Rectangle(0, 0, nWidth, nHeight));
g.TextRenderingHint = TextRenderingHint.AntiAlias;
g.DrawString(_ShowName, stringFont, new SolidBrush(Color.Red), new PointF(0, 0), stringFormat);
objBitmap.Save(Response.OutputStream, ImageFormat.Gif);
}
catch (Exception ee)
{
Response.Write(ee.ToString());
}
finally
{
if (null != g) g.Dispose();
if (null != objBitmap) objBitmap.Dispose();
Response.End();
}
生成的图片上字体都是一并齐,我想要这样一个效果,比如其中的某个数字网上提一点,另外一个数字又往下一点,这下上下参差不齐,拜托大家帮帮忙
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货