asp.net用鼠标滚轮实现图片缩放实现方法
- //************************************************************//
- //下面给出三个简单的方法,后面两个方法是扩展,估计有时用得着
- //************************************************************//
- /// <summary>
- /// 缩小图片
- /// </summary>
- /// <param name="strOldPic">源图文件名(包括路径)</param>
- /// <param name="strNewPic">缩小后保存为文件名(包括路径)</param>
- /// <param name="intWidth">缩小至宽度</param>
- /// <param name="intHeight">缩小至高度</param>
- public void SmallPic(string strOldPic, string strNewPic, int intWidth, int intHeight)
- {
- System.Drawing.Bitmap objPic,objNewPic;
- try
- {
- objPic = new System.Drawing.Bitmap(strOldPic);
- objNewPic=new System.Drawing.Bitmap(objPic,intWidth,intHeight);
- objNewPic.Save(strNewPic);
- }
- catch(Exception exp){throw exp;}
- finally
- {
- objPic=null;
- objNewPic=null;
- }
- }
- /// <summary>
- /// 按比例缩小图片,自动计算高度
- /// </summary>
- /// <param name="strOldPic">源图文件名(包括路径)</param>
- /// <param name="strNewPic">缩小后保存为文件名(包括路径)</param>
- /// <param name="intWidth">缩小至宽度</param>
- public void SmallPic(string strOldPic, string strNewPic, int intWidth)
- {
- System.Drawing.Bitmap objPic,objNewPic;
- try
- {
- objPic = new System.Drawing.Bitmap(strOldPic);
- int intHeight=(intWidth / objPic.Width) * objPic.Height;
- objNewPic=new System.Drawing.Bitmap(objPic,intWidth,intHeight);
- objNewPic.Save(strNewPic);
- }
- catch(Exception exp){throw exp;}
- finally
- {
- objPic=null;
- objNewPic=null;
- }
- }
- /// <summary>
- /// 按比例缩小图片,自动计算宽度
- /// </summary>
- /// <param name="strOldPic">源图文件名(包括路径)</param>
- /// <param name="strNewPic">缩小后保存为文件名(包括路径)</param>
- /// <param name="intHeight">缩小至高度</param>
- public void SmallPic(string strOldPic, string strNewPic, int intHeight)
- {
- System.Drawing.Bitmap objPic,objNewPic;
- try
- {
- objPic = new System.Drawing.Bitmap(strOldPic);
- int intWidth=(intHeight / objPic.Height) * objPic.Width;
- objNewPic=new System.Drawing.Bitmap(objPic,intWidth,intHeight);
- objNewPic.Save(strNewPic);
- }
- catch(Exception exp){throw exp;}
- finally
- {
- objPic=null;
- objNewPic=null;
- }
- }
asp.net用鼠标滚轮实现图片pdf缩放
- <mce:script language="javascript"><!--
- function bbimg(o)
- {
- var zoom=parseInt(o.style.zoom, 10)||100;
- zoom+=event.wheelDelta/12;
- if (zoom>0)
- o.style.zoom=zoom+'%';
- return false;
- }
- // --></mce:script>
- <img src='../FloorPicture/<%#DataBinder.EvalContainer.DataItem,"picture")%>'
- onload="javascript:
- if(this.width>screen.width*0.7)
- this.style.width=screen.width*0.7;"
- onmousewheel="return bbimg(this)">
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
- <title>用滚轮实现图片缩放</title>
- </head>
- <mce:script language="JavaScript"><!--
- function zoomimg(img){
- //img.style.zoom获取img对象的缩放比例,并转为十进制整数 pdf
- var zoom = parseInt(img.style.zoom,10);
- if (isNaN(zoom)){ //当zoom非数字时zoom默认为100%
- zoom = 100;
- }
- //event.wheelDelta滚轮移动量上移+120,下移-120;显示比例每次增减10%
- zoom += event.wheelDelta / 12;
- //当zoom大于10%时重新设置显示比例
- if (zoom>10) img.style.zoom = zoom + "%";
- }
- // --></mce:script>
- <body>
- <br>
- <!--onmousewheel:当滚轮移动时触发-->
- <img src="图片路径" mce_src="图片路径" onmousewheel="zoomimg(this)">
- </body>
- </html>
asp.net:pdf图片按比例缩放,可输入参数设定初始大小pdf
- <mce:scriptlanguage="javascript">
- <!--
- //图片按比例缩放,可输入参数设定初始大小
- functionresizeimg(ImgD,iwidth,iheight) {varimage=newImage();
- image.src=ImgD.src;if(image.width>0 && image.height>0){if(image.width/image.height>= iwidth/iheight){if(image.width>iwidth){
- ImgD.width=iwidth;
- ImgD.height=(image.height*iwidth)/image.width;
- }else{
- ImgD.width=image.width;
- ImgD.height=image.height;
- }
- ImgD.alt=image.width+"×"+image.height;
- }else{if(image.height>iheight){
- ImgD.height=iheight;
- ImgD.width=(image.width*iheight)/image.height;
- }else{
- ImgD.width=image.width;
- ImgD.height=image.height;
- }
- ImgD.alt=image.width+"×"+image.height;
- }
- ImgD.style.cursor="pointer";//改变鼠标指针
- ImgD.onclick =function() {window.open(ImgD.src);}//点击打开大图片
- if(navigator.userAgent.toLowerCase().indexOf("ie") > -1) {//判断浏览器,如果是IE
- ImgD.title ="请使用鼠标滚轮缩放图片,点击图片可在新窗口打开";
- ImgD.onmousewheel =functionimg_zoom()//滚轮缩放
- {
- varzoom = parseInt(this.style.zoom, 10) || 100;
- zoom +=event.wheelDelta / 12;
- if(zoom> 0) this.style.zoom = zoom +"%";
- returnfalse;
- }
- }else{//如果不是IE
- ImgD.title ="点击图片可在新窗口打开";
- }
- }
- }
- // -->
- </mce:script>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步