忘了BuildImage了
private string BuildImage()
{
bool blnHasPic;
if(ViewState["OldImage"] != null)
{
blnHasPic = System.IO.File.Exists(Page.Server.MapPath(ViewState["OldImage"].ToString()));
}
else
{
blnHasPic = false;
}
m_newImage = this.ClientID + ".fbs.ashx";
if(!blnHasPic && this.Width.IsEmpty)
{
this.Width = Unit.Pixel(70);
}
if(!blnHasPic && this.Height.IsEmpty)
{
this.Height = Unit.Pixel(20);
}
string strCode = ViewState["Text"].ToString();
string strFName = "System";
float floFSize = 9;
FontStyle fntstyFont = FontStyle.Regular;
if(m_Font != null)
{
if(m_Font.Name != string.Empty)
{
strFName = m_Font.Name;
}
//如果使用是的是FontSize.Large等相对值应该怎么做
if(m_Font.Size.Type != FontSize.NotSet)
{
floFSize = (float)m_Font.Size.Unit.Value;
}
else
{
floFSize = 9;
}
if(m_Font.Bold)
{
fntstyFont |= FontStyle.Bold;
}
if(m_Font.Italic)
{
fntstyFont |= FontStyle.Italic;
}
if(m_Font.Strikeout)
{
fntstyFont |= FontStyle.Strikeout;
}
if(m_Font.Underline)
{
fntstyFont |= FontStyle.Underline;
}
}
Font fntOut = new Font(strFName, floFSize, fntstyFont);
#region 生成图片
MemoryStream ms = null;
Bitmap objBitmap;
if(ViewState["OldImage"] != null)
{
objBitmap = (Bitmap)Bitmap.FromFile(Page.Server.MapPath(ViewState["OldImage"].ToString()));
}
else
{
objBitmap = new Bitmap(int.Parse(Width.Value.ToString()), int.Parse(Height.Value.ToString()));
}
Graphics objGraphics = Graphics.FromImage(objBitmap);
if(ViewState["OldImage"] == null)
{
objGraphics.FillRectangle(new SolidBrush(BackColor == Color.Empty ? Color.White : BackColor), 0, 0, objBitmap.Width, objBitmap.Height);
}
SizeF wh = objGraphics.MeasureString(strCode, fntOut);
int l = (objBitmap.Width - (int)wh.Width) / 2;
int t = (objBitmap.Height - (int)wh.Height) / 2;
for(int i = 0; i < strCode.Length; i++)
{
if(i == 0)
{
l -= (int)(objGraphics.MeasureString(strCode.Substring(i, 1), fntOut).Width / 3);
}
Matrix myMatrix = new Matrix();
myMatrix.RotateAt(i % 2 == 0 ? TextAngle : 0 - TextAngle, new PointF(l + wh.Width / 2, wh.Height / 2), MatrixOrder.Append);
objGraphics.Transform = myMatrix;
objGraphics.DrawString(strCode.Substring(i, 1), fntOut, new SolidBrush(ForeColor == Color.Empty ? Color.Black : ForeColor), l, t);
l += (int)objGraphics.MeasureString(strCode.Substring(i, 1), fntOut).Width;
}
ms = new MemoryStream();
objBitmap.Save(ms, ImageFormat.Jpeg);
AshxHandler.RegisterCacheFile(this.Page, m_newImage, ms.ToArray());
objGraphics.Dispose();
objBitmap.Dispose();
#endregion
m_IsLaod = true;
string cacheid = "." + DateTime.Now.ToString("mmfffMMyyddssHH");
this.ImageUrl = m_newImage + "?" + cacheid;
m_IsLaod = false;
return cacheid;
}