[C#]asp.net生成高清晰缩略图

摘要:
Code//////生成缩略图//////源图路径(物理路径)///缩略图路径(物理路径)///缩略图宽度///缩略图高
[C#]asp.net生成高清晰缩略图第1张[C#]asp.net生成高清晰缩略图第2张Code
///<summary>///生成缩略图
///</summary>///<paramname="originalImagePath">源图路径(物理路径)</param>///<paramname="thumbnailPath">缩略图路径(物理路径)</param>///<paramname="width">缩略图宽度</param>///<paramname="height">缩略图高度</param>publicvoidMakeThumbnail(stringoriginalImagePath,stringthumbnailPath,intwidth,intheight)
{
System.Drawing.ImageoriginalImage
=System.Drawing.Image.FromFile(originalImagePath);
inttowidth=0;
inttoheight=0;
if(originalImage.Width>width&&originalImage.Height<height)
{
towidth
=width;
toheight
=originalImage.Height;
}
if(originalImage.Width<width&&originalImage.Height>height)
{
towidth
=originalImage.Width;
toheight
=height;
}
if(originalImage.Width>width&&originalImage.Height>height)
{
towidth
=width;
toheight
=height;
}
if(originalImage.Width<width&&originalImage.Height<height)
{
towidth
=originalImage.Width;
toheight
=originalImage.Height;
}
intx=0;//左上角的x坐标inty=0;//左上角的y坐标
//新建一个bmp图片System.Drawing.Imagebitmap=newSystem.Drawing.Bitmap(towidth,toheight);
//新建一个画板Graphicsg=System.Drawing.Graphics.FromImage(bitmap);
//设置高质量插值法g.InterpolationMode=System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度g.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//清空画布并以透明背景色填充g.Clear(Color.Transparent);
//在指定位置并且按指定大小绘制原图片的指定部分g.DrawImage(originalImage,x,y,towidth,toheight);
try
{
//以jpg格式保存缩略图bitmap.Save(thumbnailPath,System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch(System.Exceptione)
{
throwe;
}
finally
{
originalImage.Dispose();
bitmap.Dispose();
g.Dispose();
}
}

免责声明:文章转载自《[C#]asp.net生成高清晰缩略图》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Graphics2D画图时背景颜色设置使用EasyExcel导出图片及异常处理下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

system函数遇到的问题

这几天调程序(嵌入式linux),发现程序有时就莫名其妙的死掉,每次都定位在程序中不同的system()函数,直接在shell下输入system()函数中调用的命令也都一切正常.就没理这个bug,以为是其他的代码影响到这个,或是内核驱动文件系统什么的异常导致,昨天有出现了这个问题,就随手百了一下度,问题出现了,很多人都说system()函数要慎用要少用...

ASP.NET Web应用程序修改页面Inherits示例

<@page 中 Codebehind 、Inherits 和aspx的关系 CodeBehind 指定包含与页关联的类的已编译文件的名称。该属性不能在运行时使用。 说明: 提供此属性是为了与以前版本的 ASP.NET 的兼容,以实现代码隐藏功能。在 ASP.NET 2.0 版中,应改用 CodeFile 属性指定该源文件的名称,同时使用 Inher...

k8s 证书创建

一 证书分类 服务器证书: server cert :用户客户端验证服务端的身份。 客户端证书: client cert:用户服务端验证客户端的身份。 对等证书: peer cert: 用户成员之间的身份验证,例如etcd,(该证书,它即是server cert,又是client cert)。   二 k8s集群证书的分类 ETCD: 需要server c...

[转]如何利用ndk-stack工具查看so库的调用堆栈【代码示例】?

如何利用ndk-stack工具查看so库的调用堆栈【代码示例】? http://hi.baidu.com/subo4110/item/d00395b3bf63e4432bebe36d Step1:Android应用主文件:CPPTestActivity.java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18...

awk 调用 shell 命令,并传递参数

from:awk 调用 shell 命令的两种方法:system 与 print shell 向awk传递命令,这样使用即可: awk -v  ...  但反过来呢?awk调用外部命令,同时也传参呢?  awk 中使用的 shell 命令,有 2 种方法:一。使用所以 system()awk 程序中我们可以使用 system() 函数去调用 shell...

StringBuilder类

   ===================================================================================================================== 2.String与StringBuilder原理对比  ============================...