• ----:)欢迎访问源码网(:----
    • 首页
    • 博客
    • 学院
    • 下载
    • 论坛
    • 影视
    • 发布源码
    • RSS
    • ITPig
    • 笑话网
    • 百家姓
    • 繁體中文

源码网 - 中国第一源码门户
选择镜像:网通镜像 - 电信主站
  • 首 页
  • 新闻动态
  • 网站运营
  • 网页制作
  • WEB开发
  • 编程开发
  • 图像媒体
  • 操作系统
  • 数据库
  • 服务器
热门搜索 优化 SEO 故事 cms IIS7 MySQL 个人 AdSense 主题推广 | 文章搜索: 高级搜索
会员登录/控制面版您的位置: 学院首页 >> WEB开发 >> .NET 开发 >> 详细内容
 

推荐文章

 
 

热点文章

  • FckEditor远程图片下载插件
  • TFS(Team Foundation Server)使用经验
  • IIS过滤器实现.NET程序不破解DLL替换字符串一法
  • 为ASP.NET封装的SQL数据库访问类
  • ASP.NET2.0中文验证码的实现
  • Url地址重写,利用HttpHander手工编译页面并按需生成静..
  • ASP.NET学习笔记一——ASP和ASP.NET比较
  • 使用HtmlInputHidden 控件在本页面保持状态和跨页面传..
  • ASP.Net发邮件
  • Silverlight 2.0中文学习资源集萃
  • WinForm中使用XtraGrid控件,实现在界面中动态修改列显..
  • 解析ASP.NET木马文件操作
 
 

相关文章

 
 

百度搜索

 
 

asp.net生成缩略图及给原始图加水印

  • 阅览次数:
  • 文章来源: CodePub整理
  • 原文作者:
  • 整理日期: 2008-01-21
  • 发表评论
  • 字体大小:
  • 小
  • 中
  • 大

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;
}

上一篇:PHP使用zlib扩展实现页面GZIP压缩输出
下一篇:构建支持Master/Slave读写分离的数据库操作类
  • 网友评论:
  • 查看所有评论
  • 我要发表评论
您的网名:
留言主题:
你要发表的内容:

 

关于本站 | 广告联系 | 版权声明 | 网站地图 | 发布软件 | 帮助中心 | 源码论坛

Copyright © 2005-2007 CodePub.Com  程序支持:木翼  滇ICP备05005971号