略缩图的方法
来源:互联网 发布:神经内科 知乎 编辑:程序博客网 时间:2024/04/29 22:34
//生成缩略图
//MyPostFile 上传的图片文件
//SavaPath 保存缩略图完整路径
//MyWidth 缩略图的宽度
//MyHeight 缩略图的高度
public void SmallImgW(System.Web.HttpPostedFile MyPostFile, string SavePath, System.Double MyWidth, System.Double MyHeight)
{ //取得图片对象
System.Drawing.Image myimage=System.Drawing.Image.FromStream(MyPostFile.InputStream,true);
//判断原图片大小 指定高宽裁减(不变形)
System.Double newwidth, newheight;
if (myimage.Width > myimage.Height)
{
newwidth = MyWidth;
newheight = myimage.Height * (newwidth / myimage.Width);
}
else
{
newheight = MyHeight;
newwidth = (newheight / myimage.Height) * myimage.Width;
}
//新建一个bmp图片
System.Drawing.Image mybitmap = new System.Drawing.Bitmap((int)newwidth, (int)newheight);
//新建一个画板
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(mybitmap);
//设置高质量插值法
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//清空画布并以透明背景色填充
g.Clear(System.Drawing.Color.Transparent);
//在指定位置画图
g.DrawImage(myimage, new System.Drawing.Rectangle(0, 0, mybitmap.Width,mybitmap.Height),new System.Drawing.Rectangle(0, 0, myimage.Width,myimage.Height),System.Drawing.GraphicsUnit.Pixel);
try
{
//以jpg格式保存缩略图
mybitmap.Save(SavePath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (System.Exception e)
{
throw e;
}
finally
{
//释放对象
myimage.Dispose();
mybitmap.Dispose();
g.Dispose();
}
}
//MyPostFile 上传的图片文件
//SavaPath 保存缩略图完整路径
//MyWidth 缩略图的宽度
//MyHeight 缩略图的高度
public void SmallImgW(System.Web.HttpPostedFile MyPostFile, string SavePath, System.Double MyWidth, System.Double MyHeight)
{ //取得图片对象
System.Drawing.Image myimage=System.Drawing.Image.FromStream(MyPostFile.InputStream,true);
//判断原图片大小 指定高宽裁减(不变形)
System.Double newwidth, newheight;
if (myimage.Width > myimage.Height)
{
newwidth = MyWidth;
newheight = myimage.Height * (newwidth / myimage.Width);
}
else
{
newheight = MyHeight;
newwidth = (newheight / myimage.Height) * myimage.Width;
}
//新建一个bmp图片
System.Drawing.Image mybitmap = new System.Drawing.Bitmap((int)newwidth, (int)newheight);
//新建一个画板
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(mybitmap);
//设置高质量插值法
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//清空画布并以透明背景色填充
g.Clear(System.Drawing.Color.Transparent);
//在指定位置画图
g.DrawImage(myimage, new System.Drawing.Rectangle(0, 0, mybitmap.Width,mybitmap.Height),new System.Drawing.Rectangle(0, 0, myimage.Width,myimage.Height),System.Drawing.GraphicsUnit.Pixel);
try
{
//以jpg格式保存缩略图
mybitmap.Save(SavePath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (System.Exception e)
{
throw e;
}
finally
{
//释放对象
myimage.Dispose();
mybitmap.Dispose();
g.Dispose();
}
}
- 略缩图的方法
- 如何生成网页的略缩图?
- [C#] 生成略缩图
- [C#] 生成略缩图
- [C#] 生成略缩图
- [C#] 生成略缩图
- [C#] 生成略缩图
- [C#] 生成略缩图
- php略缩图
- 对以前的改进MFC略缩图控件改进
- jQuery Lightbox Plugin-经典的略缩图查看插件
- android获取多个在线视频的略缩图
- android中实现ImageView中显示视频的略缩图
- MFC略缩图控件实现
- java自动生成略缩图
- android获取在线视频略缩图
- PHP等比例缩图的方法
- 图片生成指定大小的略缩图(只支持JPG)
- 最近关注
- 架构根据电信、网通用户自动解析不同IP的DNS服务器
- 使用vc 编译 wpcap.dll(WpcapSrc_4_0_2.zip版本)时 struct sockaddr_storage编译通不过的解决方法.
- 使用JScript.encode进行网页的加密与解密
- 邀请:数据挖掘/搜索/机器学习相关算法研究生
- 略缩图的方法
- 2008----计算机 教条
- 类似网易163主页的选项卡效果代码
- 浅析C++中的this指针
- WDZ概览
- The Hardest Problem Ever
- 获取java线程中信息的两种方法
- 项目管理知识积累
- 复习新托福iBT英文写作经验汇总