zoukankan
html css js c++ java
asp.net上传图片并同时生成缩略图
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))); } //生成缩略原图 Bitmap tImage = new Bitmap(tWidth, tHeight); Graphics g = Graphics.FromImage(tImage); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置高质量插值法 g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;//设置高质量,低速度呈现平滑程度 g.Clear(Color.Transparent); //清空画布并以透明背景色填充 g.DrawImage(oImage, new Rectangle(0, 0, tWidth, tHeight), new Rectangle(0, 0, oWidth, oHeight), GraphicsUnit.Pixel); string oFullName = Server.MapPath(".") + "/image/" + "o" + DateTime.Now.ToShortDateString().Replace("-", "") + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + ".jpg"; //保存原图的物理路径 string tFullName = Server.MapPath(".") + "/image/" + "t" + DateTime.Now.ToShortDateString().Replace("-", "") + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + ".jpg"; //保存缩略图的物理路径 try { //以JPG格式保存图片 oImage.Save(oFullName, System.Drawing.Imaging.ImageFormat.Jpeg); tImage.Save(tFullName, System.Drawing.Imaging.ImageFormat.Jpeg); } catch (Exception ex) { throw ex; } finally { //释放资源 oImage.Dispose(); g.Dispose(); tImage.Dispose(); } } }
查看全文
相关阅读:
N 种仅仅使用 HTML/CSS 实现各类进度条的方式
使用 CSS 轻松实现一些高频出现的奇形怪状按钮
通过jdb命令连接远程调试的方法
(转)Python中asyncio与aiohttp入门教程
(转)从0到1,Python异步编程的演进之路
(转)python︱用asyncio、aiohttp实现异步及相关案例
(转)Python 如何仅用5000 行代码,实现强大的 logging 模块?
(转)python的dict()字典数据类型的方法详解以及案例使用
(转)Python Async/Await入门指南
(转)Python运维自动化psutil 模块详解(超级详细)
原文地址:https://www.cnblogs.com/javawebsoa/p/2458099.html
最新文章
redis后台启动
阿里云快速搭建Spring Boot环境(Java,IntelliJ IDEA)
阿里云快速搭建Hadoop环境
阿里云快速搭建LNMP环境(MySQL,Nginx,PHP)
阿里云搭建微信小程序
Failed to execute goal org.apache.maven.plugins:mavencompilerplugin:3.1:compile (defaultcompile) on project msmcms: Compilation failure
markdown常用语法
阿里云搭建云上博客
微信小程序 引入DayJS 用于时间处理
微信小程序Echarts 二次渲染失败 及 组件监听父页面传递值的变化 及 wx.navigateBack 目标页面Onload 不加载问题
热门文章
小程序发布后,提示用户更新最新版本代码
微信小程序定时执行及清除定时器 及 this.setData({}) 设置对象内属性
微信小程序,防止表单数据丢失,表单返回提示框 wx.enableAlertBeforeUnload ,需要真机预览才有效果哦
小程序圆角设计及position: fixed 适应安卓手机电柜详情随笔记录
利用 clippath 实现动态区域裁剪
巧用渐变实现高级感拉满的背景光动画
Amazing!!CSS 也能实现极光?
Amazing!!CSS 也能实现烟雾效果?
巧用滤镜实现高级感拉满的文字快闪切换效果
3D 穿梭效果?使用 CSS 轻松搞定
Copyright © 2011-2022 走看看