生成缩略图 C#源码
#region 获取缩略图
/// <summary>
/// 获取缩略图
/// </summary>
/// <param name="imgPath">要做缩略图的图片路径</param>
/// <param name="savePaty">保存缩略图的路径</param>
/// <returns>是否成功</returns>
public static bool makeListImage(string imgPath, string savePaty)
{
try
{
System.Drawing.Image img = System.Drawing.Image.FromFile(imgPath);
Graphics g = Graphics.FromImage(img);
Font font = new Font("宋体", 14);
Brush brush = Brushes.Black;
g.DrawString("100wx.com", font, brush, 3, 3);
//创建委托
System.Drawing.Image.GetThumbnailImageAbort callback = new System.Drawing.Image.GetThumbnailImageAbort(gett);
img = img.GetThumbnailImage(45, 45, callback, new IntPtr());
img.Save(savePaty, System.Drawing.Imaging.ImageFormat.Jpeg);
g.Dispose();
img.Dispose();
//PPD1aGlm
}
catch { return false; }
return true;
}
public static bool gett()
{
return true;
}
#endregion
貌似用.NET自带的生成缩略图的方法会失真
/// <summary>
/// 获取缩略图
/// </summary>
/// <param name="imgPath">要做缩略图的图片路径</param>
/// <param name="savePaty">保存缩略图的路径</param>
/// <returns>是否成功</returns>
public static bool makeListImage(string imgPath, string savePaty)
{
try
{
System.Drawing.Image img = System.Drawing.Image.FromFile(imgPath);
Graphics g = Graphics.FromImage(img);
Font font = new Font("宋体", 14);
Brush brush = Brushes.Black;
g.DrawString("100wx.com", font, brush, 3, 3);
//创建委托
System.Drawing.Image.GetThumbnailImageAbort callback = new System.Drawing.Image.GetThumbnailImageAbort(gett);
img = img.GetThumbnailImage(45, 45, callback, new IntPtr());
img.Save(savePaty, System.Drawing.Imaging.ImageFormat.Jpeg);
g.Dispose();
img.Dispose();
//PPD1aGlm
}
catch { return false; }
return true;
}
public static bool gett()
{
return true;
}
#endregion
貌似用.NET自带的生成缩略图的方法会失真