asp.net实现生成缩略图及给原始图加水印的方法示例
 更新时间:2017年10月09日 11:57:24   作者:happymagic  

这篇文章主要介绍了asp.net实现生成缩略图及给原始图加水印的方法,结合具体实例形式分析了asp.net图片的缩略图与水印操作相关实现技巧,需要的朋友可以参考下

本文实例讲述了asp.net实现生成缩略图及给原始图加水印的方法。分享给大家供大家参考,具体如下:

using System.IO;
using System.Drawing.Imaging;
private void Button1_ServerClick(object sender, System.EventArgs e)
{
Graphics g=null;
System.Drawing.Image upimage=null;
System.Drawing.Image thumimg=null;
System.Drawing.Image simage=null;
Bitmap outputfile=null;
try
{
string extension = Path.GetExtension(File1.PostedFile.FileName).ToUpper();
string filename = DateTime.Now.ToString(“yyyyMMddhhmmss”);
string smallpath = Server.MapPath(“.”)+”/smallimg/”;
string bigpath = Server.MapPath(“.”)+”/bigimg/”;
int width,height,newwidth,newheight;
System.Drawing.Image.GetThumbnailImageAbort callb =new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
if(!Directory.Exists(smallpath))
Directory.CreateDirectory(smallpath);
if(!Directory.Exists(bigpath))
Directory.CreateDirectory(bigpath);
Stream upimgfile = File1.PostedFile.InputStream;
string simagefile = Server.MapPath(“a8logo.jpg”); //要加水印的文件
simage=System.Drawing.Image.FromFile(simagefile);
upimage= System.Drawing.Image.FromStream(upimgfile); //上传的图片
width = upimage.Width;
height = upimage.Height;
if(width>height)
{
newwidth=200;
newheight =(int)((double)height/(double)width * (double)newwidth);
} else
{
newheight=200;
newwidth=(int)((double)width/(double)height * (double)newheight);
}
thumimg = upimage.GetThumbnailImage(newwidth,newheight,callb,IntPtr.Zero);
outputfile=new Bitmap(upimage);
g=Graphics.FromImage(outputfile);
g.DrawImage(simage,new Rectangle(upimage.Width-simage.Width,upimage.Height-simage.Height,upimage.Width,upimage.Height),0,0,upimage.Width,upimage.Height,GraphicsUnit.Pixel);
string newpath = bigpath + filename + extension; //原始图路径
string thumpath = smallpath + filename + extension; //缩略图路径
outputfile.Save(newpath);
thumimg.Save(thumpath);
outputfile.Dispose();
}
catch(Exception ex)
{
throw ex;
}
finally
{
if(g!=null)
g.Dispose();
if(thumimg!=null)
thumimg.Dispose();
if(upimage!=null)
upimage.Dispose();
if(simage!=null)
simage.Dispose();
}
}
public bool ThumbnailCallback()
{
return false;
}

更多关于asp.net相关内容感兴趣的读者可查看本站专题:《asp.net字符串操作技巧汇总》、《asp.net操作XML技巧总结》、《asp.net操作json技巧总结》、《asp.net文件操作技巧汇总》、《asp.net ajax技巧总结专题》及《asp.net缓存操作技巧总结》。
希望本文所述对大家asp.net程序设计有所帮助。

您可能感兴趣的文章:ASP.NET简单好用功能齐全图片上传工具类(水印、缩略图、裁剪等)asp.net上传图片并作处理水印与缩略图的实例代码asp.net文件上传功能(单文件,多文件,自定义生成缩略图,水印)ASP.Net 上传图片并生成高清晰缩略图asp.net图片上传生成缩略图的注意事项asp.net 上传图片并同时生成缩略图的代码ASP.NET实现上传图片并生成缩略图的方法Asp.net 文件上传类(取得文件后缀名,保存文件,加入文字水印)asp.net 添加水印的代码(已测试)asp.net下GDI+的一些常用应用(水印,文字,圆角处理)技巧asp.net如何在图片上加水印文字具体实现

asp.net
缩略图
水印

相关文章
ASP.NET GridView 实现课程表显示(动态合并单元格)实现步骤GridView,ASP.NET中很常用的数据显示控件,这里,我将用这个控件来实现课程表的显示。首先说说课程表的显示与普通记录的显示有何不同?感兴趣的朋友可以了解下,或许对你有所帮助 2013-02-02
.Net 垃圾回收机制详细介绍这篇文章主要介绍了.Net 垃圾回收机制详细介绍的相关资料,这里对垃圾回收机制做了详细的讲解,需要的朋友可以参考下 2016-11-11
ASP.NET验证码实现(附源码)这篇文章主要介绍了ASP.NET验证码实现过程,并为大家分享了源码下载,感兴趣的小伙伴们可以参考一下 2015-11-11
asp.net实现的群发邮件功能详解这篇文章主要介绍了asp.net实现的群发邮件功能,结合具体实例形式分析了asp.net基于SMTP服务群发QQ邮件的相关操作技巧与注意事项,需要的朋友可以参考下 2017-05-05
MVC+EasyUI+三层新闻网站建立 后台登录界面的搭建(二)这篇文章主要为大家详细介绍了MVC+EasyUI+三层新闻网站建立的第二篇,教大家如何搭建后台登录界面,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 2017-07-07
asp.net中穿透Session 0 隔离(一)服务(Service)对于大家来说一定不会陌生,它是Windows 操作系统重要的组成部分。我们可以把服务想像成一种特殊的应用程序,它随系统的“开启~关闭”而“开始~停止”其工作内容,在这期间无需任何用户参与 2012-11-11
ASP.NET中防止页面刷新造成表单重复提交执行两次操作本文主要介绍在Session存储唯一标识Token,通过和后台对比,以实现防止刷新提交表单的问题。 2016-04-04
ASP.NET2.0数据库入门之SqlDataSourceASP.NET2.0数据库入门之SqlDataSource… 2006-09-09
asp.net Repeater 自递增asp.net Repeater 自递增,方便需要递增输出数列的朋友 2009-02-02
Asp.NET调用百度翻译的方法这篇文章主要介绍了Asp.NET调用百度翻译的方法,是针对百度接口开发的经典实用技巧,非常具有实用价值,需要的朋友可以参考下 2015-02-02

最新评论

声明:本站(华域联盟www.cnhackhy.com)所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。