/// <summary>
/// 保存小图(文字水印)
/// </summary>
/// <param name="savePath">保存小图的完整路径</param>
/// <param name="w">小图宽度</param>
/// <param name="h">小图高度</param>
/// <param name="Title">画在图上的水印文字</param>
/// <param name="fontsize">文字的大小</param>
/// <param name="ImagePath">原图的完整路径</param>
public bool SaveSmallImg(string savePath, int w, int h, string Title, int fontsize, string ImagePath)
{
if (ImagePath == null || savePath == null)
{
return false;
}
Bitmap Img = new Bitmap(ImagePath);
int w0 = 0;
int h0 = 0;
if (Img.Width / Img.Height >= w / h )
{
h0 = h;
w0 = h0 * Img.Width / Img.Height;
}
else
{
w0 = w;
h0 = w0 * Img.Height / Img.Width;
}
Bitmap bit = new Bitmap(w0, h0);
Graphics gp = Graphics.FromImage(bit);
gp.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
gp.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
gp.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
gp.Clear(System.Drawing.Color.Transparent);
gp.DrawImage(Img, new Rectangle(0, 0, w0, h0)); gp.SmoothingMode = SmoothingMode.AntiAlias;
// new SolidBrush(Color.FromArgb(180,70,140,140))透明程度
gp.DrawString(Title, new Font("华文彩云", fontsize), new SolidBrush(Color.FromArgb(180,70,140,140)), new PointF(10, bit.Height - fontsize - 15));
bit.Save(savePath, ImageFormat.Jpeg);
Img.Dispose();
bit.Dispose();
return true;
}
发生GDI+一般性错误,请问怎么办,请高人帮忙谢谢,分没55555555555
/// 保存小图(文字水印)
/// </summary>
/// <param name="savePath">保存小图的完整路径</param>
/// <param name="w">小图宽度</param>
/// <param name="h">小图高度</param>
/// <param name="Title">画在图上的水印文字</param>
/// <param name="fontsize">文字的大小</param>
/// <param name="ImagePath">原图的完整路径</param>
public bool SaveSmallImg(string savePath, int w, int h, string Title, int fontsize, string ImagePath)
{
if (ImagePath == null || savePath == null)
{
return false;
}
Bitmap Img = new Bitmap(ImagePath);
int w0 = 0;
int h0 = 0;
if (Img.Width / Img.Height >= w / h )
{
h0 = h;
w0 = h0 * Img.Width / Img.Height;
}
else
{
w0 = w;
h0 = w0 * Img.Height / Img.Width;
}
Bitmap bit = new Bitmap(w0, h0);
Graphics gp = Graphics.FromImage(bit);
gp.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
gp.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
gp.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
gp.Clear(System.Drawing.Color.Transparent);
gp.DrawImage(Img, new Rectangle(0, 0, w0, h0)); gp.SmoothingMode = SmoothingMode.AntiAlias;
// new SolidBrush(Color.FromArgb(180,70,140,140))透明程度
gp.DrawString(Title, new Font("华文彩云", fontsize), new SolidBrush(Color.FromArgb(180,70,140,140)), new PointF(10, bit.Height - fontsize - 15));
bit.Save(savePath, ImageFormat.Jpeg);
Img.Dispose();
bit.Dispose();
return true;
}
发生GDI+一般性错误,请问怎么办,请高人帮忙谢谢,分没55555555555
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货