c#生成缩略图
2005-10-14 20:42
197 查看
private void ShowThumbnail(string oldfile, string newfile, int h, int w)
{
System.Drawing.Image img = System.Drawing.Image.FromFile(oldfile);
System.Drawing.Image.GetThumbnailImageAbort myCallback = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
int oldh = img.Height;
int oldw = img.Width;
int newh,neww;
double h1 = oldh*1.0/h;
double w1 = oldw*1.0/w;
double f = (h1>w1)? h1:w1;
if(f < 1.0)
{
newh = oldh;
neww = oldw;
}
else
{
newh = (int)(oldh/f);
neww = (int)(oldw/f);
}
System.Drawing.Image myThumbnail = img.GetThumbnailImage(neww, newh, myCallback, IntPtr.Zero);
myThumbnail.Save(newfile, System.Drawing.Imaging.ImageFormat.Jpeg);
img.Dispose();
myThumbnail.Dispose();
}
private bool ThumbnailCallback()
{
return false;
}
{
System.Drawing.Image img = System.Drawing.Image.FromFile(oldfile);
System.Drawing.Image.GetThumbnailImageAbort myCallback = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
int oldh = img.Height;
int oldw = img.Width;
int newh,neww;
double h1 = oldh*1.0/h;
double w1 = oldw*1.0/w;
double f = (h1>w1)? h1:w1;
if(f < 1.0)
{
newh = oldh;
neww = oldw;
}
else
{
newh = (int)(oldh/f);
neww = (int)(oldw/f);
}
System.Drawing.Image myThumbnail = img.GetThumbnailImage(neww, newh, myCallback, IntPtr.Zero);
myThumbnail.Save(newfile, System.Drawing.Imaging.ImageFormat.Jpeg);
img.Dispose();
myThumbnail.Dispose();
}
private bool ThumbnailCallback()
{
return false;
}
相关文章推荐
- 关于生成缩略图:c#
- C#上传图片和生成缩略图以及图片预览
- c# 生成缩略图
- C#生成缩略图代码
- C#生成缩略图不清晰模糊问题的解决方案!
- C#生成缩略图控件
- [收藏]ASP.NET生成高质量缩略图通用函数(VB.NET、c#代码)
- .net C# 生成缩略图 用白色填充空白部分
- 使用ASP.net(C#)批量上传图片并自动生成缩略图,文字水印图,图片水印图
- c#生成缩略图
- asp.net生成高质量缩略图通用函数(c#代码),支持多种生成方式
- ASP.NET C# 生成不失真的缩略图
- C#生成缩略图(等比例,水平、垂直方向居中,画布白色背景填充)
- asp.net生成高质量缩略图通用函数(c#代码),支持多种生成方式
- asp.net 中如何得到图片的高度(height)和宽度(width)以及生成图片的缩略图 C#
- 生成网站缩略图代码(C#)
- c#生成缩略图
- c#生成缩略图不失真的方法实例分享
- 使用ASP.net(C#)批量上传图片并自动生成缩略图,文字水印图,图片水印图
- 黄聪:C#图片处理封装类(裁剪、缩放、清晰度、加水印、生成缩略图)有示例(转)