asp.net上传图片并同时生成缩略图

来源:未知 责任编辑:责任编辑 发表时间:2013-12-06 08:45 点击:
using System; 
using System.Data; 
using System.Configuration; 
using System.Collections; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 
using System.Drawing; 
public partial class slt_Default : System.Web.UI.Page 

    protected void Page_Load(object sender, EventArgs e) 
    { 
    } 
    protected void bt_upload_Click(object sender, EventArgs e) 
    { 
        //检查上传文件的格式是否有效  
        if (this.UploadFile.PostedFile.ContentType.ToLower().IndexOf("image") < 0) 
        { 
            Response.Write("上传图片格式无效!"); 
            return; 
        } 
        //生成原图  
        Byte[] oFileByte = new byte[this.UploadFile.PostedFile.ContentLength]; 
        System.IO.Stream oStream = this.UploadFile.PostedFile.InputStream; 
        System.Drawing.Image oImage = System.Drawing.Image.FromStream(oStream); 
        int oWidth = oImage.Width; //原图宽度  
        int oHeight = oImage.Height; //原图高度  
        int tWidth = 100; //设置缩略图初始宽度  
        int tHeight = 100; //设置缩略图初始高度 
        //按比例计算出缩略图的宽度和高度  
        if (oWidth >= oHeight) 
        { 
            tHeight = (int)Math.Floor(Convert.ToDouble(oHeight) * (Convert.ToDouble(tWidth) / Convert.ToDouble(oWidth))); 
        } 
        else 
        { 
            tWidth = (int)Math.Floor(Convert.ToDouble(oWidth) * (Convert.ToDouble(tHeight) / Convert.ToDouble(oHeight))); 
        } 
        //生成缩略原图  
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • 浅析.NET下XML数据访问新机制
  • asp.net 面试+笔试题目第1/2页
  • C# 邮件地址是否合法的验证
  • asp.net 设置GridView的选中行的实现代码
  • C#高级编程:数据库连接[1]
  • 经典C++程序1
  • IIS 自动回收导致后台定时器失效的问题解决
  • ASP.NET&#160;GridView列表代码示例
  • Asp.net MVC源码分析--Action Filter的链式调用
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1