博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
aspx上传、预览图片
阅读量:4050 次
发布时间:2019-05-25

本文共 4018 字,大约阅读时间需要 13 分钟。

//aspx 
//javascript //显示图片 function over() { //图片的最大大小 4/3的大小 520 390 maxwidth=520; maxheight=390; //显示 document.getElementById('divImage').style.display=""; //设置div的位置 var obj= document.getElementById('divImage'); obj.style.left=316; obj.style.bottom=115;//202 115 //获取img 设置图片的大小 var img=document.getElementById('divImage').firstChild; //1、宽和高都超过了,看谁超过的多,其余策略按照2、3 //2、如果宽超过了并且高没有超,设置宽为最大值 //3、如果宽没超过并且高超过了,设置高为最大值 if(img.width>maxwidth&&img.height>maxheight) { pare=(img.width-maxwidth)-(img.height-maxheight); if(pare>=0) img.width=maxwidth; else img.height=maxheight; } else if(img.width>maxwidth&&img.height<=maxheight) { img.width=maxwidth; } else if(img.width<=maxwidth&&img.height>maxheight) { img.height=maxheight; } else { } } //隐藏图片 function out() { document.getElementById('divImage').style.display="none"; } //后台 #region 图片相关操作 /// /// 预览图片按钮事件 /// /// /// protected void btn_Upload_Click(object sender, EventArgs e) { PictureSee(); } /// /// 预览图片 /// ///
预览结果:0、成功;1、失败
protected int PictureSee() { //支持的扩展名,必须小写 string strImageType = "jpg/jpeg/gif"; //最大数据量 单位kb int intMaxData = 500; //图片名 string strFileName = fileImageData.FileName; //判断是否存在图片 if (strFileName != null && strFileName != "") { //获取文件的扩展名,转化成小写形式,并判断是否支持该扩展名 if (strImageType.Contains(strFileName.Split('.')[1].ToLower())) { byte[] buffer = fileImageData.FileBytes; //判断图片大小 int x = buffer.Length; if (x / 1024 > intMaxData) { Alert("图片文件太大,不能超过500k!"); return 1; } else { //开始预览 Session["image"] = buffer; this.imgshow.ImageUrl = "~/Pages/MatlCategoryManagerMod/ShowImage.aspx"; this.imgbig.ImageUrl = "~/Pages/MatlCategoryManagerMod/ShowImage.aspx"; } } else { Alert("不支持此扩展名图片!"); return 1; } } return 0; } #endregion显示用aspx /// /// 页面初始化 /// /// /// protected void Page_Load(object sender, EventArgs e) { //查询数据库获取图片 if (Request["传过来的参数名"] != null) { //查询 DataSet ds = 从数据库中查询 byte[] img = null; if (ds.Tables.Count > 0) { DataTable dtimg = ds.Tables[0]; if (dtimg.Rows.Count > 0) { if (!(dtimg.Rows[0]["BPICTCONTENT"] is System.DBNull)) { //显示图片 img = (byte[])dtimg.Rows[0]["BPICTCONTENT"] as byte[]; Session["image"] = img; Response.ContentType = "application/octet-stream"; Response.BinaryWrite(img); Response.End(); } } } } else //显示session中的图片 { if (Session["image"] != null) { //显示图片 byte[] img = (byte[])Session["image"]; Response.ContentType = "application/octet-stream"; Response.BinaryWrite(img); Response.End(); } } }

 

转载地址:http://vhdci.baihongyu.com/

你可能感兴趣的文章
Win10+VS+ESP32环境搭建
查看>>
android 代码实现圆角
查看>>
flutter-解析json
查看>>
android中shader的使用
查看>>
java LinkedList与ArrayList迭代器遍历和for遍历对比
查看>>
drat中构造方法
查看>>
JavaScript的一些基础-数据类型
查看>>
JavaScript基础知识(2)
查看>>
转载一个webview开车指南以及实际项目中的使用
查看>>
android中对于非属性动画的整理
查看>>
一个简单的TabLayout的使用
查看>>
ReactNative使用Redux例子
查看>>
Promise的基本使用
查看>>
coursesa课程 Python 3 programming 统计文件有多少单词
查看>>
coursesa课程 Python 3 programming 输出每一行句子的第三个单词
查看>>
Returning a value from a function
查看>>
coursesa课程 Python 3 programming Functions can call other functions 函数调用另一个函数
查看>>
coursesa课程 Python 3 programming The while Statement
查看>>
course_2_assessment_6
查看>>
coursesa课程 Python 3 programming course_2_assessment_7 多参数函数练习题
查看>>