GDI 图片加字的重新保存的问题
Jaron 2005-02-16 02:23:48 if (System.IO.File.Exists(Server.MapPath(strSourcefile)))
{
System.Drawing.Image OldImage = new Bitmap(System.Drawing.Image.FromFile(Server.MapPath(strSourcefile)));
string strFileExt = strSourcefile.Substring(strSourcefile.LastIndexOf("."));
intImageWidth = OldImage.Width;
intImageHeight = OldImage.Height;
System.Drawing.Brush PhotoBrush = new TextureBrush(OldImage);
System.Drawing.Bitmap Img = new System.Drawing.Bitmap(intImageWidth,intImageHeight);
Graphics g = Graphics.FromImage(Img);
Color Old_Color = ColorTranslator.FromHtml("#FFFFFF");
g.Clear(Old_Color);
g.FillRectangle(PhotoBrush,0,0,intImageWidth,intImageHeight);
Color Advertisement_Color = ColorTranslator.FromHtml("#FFFFFF");
if (boolIsBlod) MyFontStyle_A = (FontStyle)System.Enum.Parse(typeof(FontStyle),"Bold");
else MyFontStyle_A = FontStyle.Regular;
Font AddString_Font = new Font(strAdd_ons_Word_fontname,float.Parse(intAdd_ons_Word_FontSize.ToString()),MyFontStyle_A);
string strFontWidth = g.MeasureString(strCopyRight, AddString_Font).Width.ToString();
string strFontHeight = g.MeasureString(strCopyRight, AddString_Font).Height.ToString();
int intFontWidth = (int)g.MeasureString(strCopyRight, AddString_Font).Width;
int intFontHeight = (int)g.MeasureString(strCopyRight, AddString_Font).Height;
int intCPY_X = (intImageWidth - intFontWidth)/2 + intAdd_ons_Word_X;
int intCPY_Y = (intImageHeight - intFontHeight)/2 + intAdd_ons_Word_Y;
if (intCPY_X <= 0) intCPY_X = 1;
if (intCPY_Y <= 0) intCPY_Y = 1;
Point Advertisement_Point = new Point(intCPY_X,intCPY_Y);
g.DrawString(strCopyRight,AddString_Font,new System.Drawing.SolidBrush(Advertisement_Color),Advertisement_Point);
System.IO.MemoryStream ms=new System.IO.MemoryStream();
Img.Save(Server.MapPath(strSourcefile),System.Drawing.Imaging.ImageFormat.Jpeg); //此行出错
OldImage.Dispose();
PhotoBrush.Dispose();
g.Dispose();
Img.Dispose();
Response.End();
}
GDI+ 中发生一般性错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Runtime.InteropServices.ExternalException: GDI+ 中发生一般性错误。
已经排除路径和权限的问题,更名后可以保存,不知道问题出在哪儿了。。。