爱学习受.NET

www.icjyw.com 记录开发技术收藏天地
公告信息
www.icjyw.com 记录开发技术收藏天地
文章分类
文章档案
文章
asp.net用鼠标滚轮实现图片缩放实现方法
2011/7/26 13:28:43
  1. //************************************************************//    
  2.  //下面给出三个简单的方法,后面两个方法是扩展,估计有时用得着     
  3.  //************************************************************//     
  4.  /// <summary>     
  5.  /// 缩小图片     
  6.  /// </summary>     
  7.  /// <param name="strOldPic">源图文件名(包括路径)</param>     
  8.  /// <param name="strNewPic">缩小后保存为文件名(包括路径)</param>     
  9. /// <param name="intWidth">缩小至宽度</param>    
  10. /// <param name="intHeight">缩小至高度</param>    
  11. public void SmallPic(string strOldPic, string strNewPic, int intWidth, int intHeight)   
  12. {   
  13.   
  14. System.Drawing.Bitmap objPic,objNewPic;   
  15. try   
  16. {   
  17. objPic = new System.Drawing.Bitmap(strOldPic);   
  18. objNewPic=new System.Drawing.Bitmap(objPic,intWidth,intHeight);   
  19. objNewPic.Save(strNewPic);   
  20.   
  21. }   
  22. catch(Exception exp){throw exp;}   
  23. finally   
  24. {   
  25. objPic=null;   
  26. objNewPic=null;   
  27. }   
  28. }   
  29.   
  30. /// <summary>    
  31. /// 按比例缩小图片,自动计算高度    
  32. /// </summary>    
  33. /// <param name="strOldPic">源图文件名(包括路径)</param>    
  34. /// <param name="strNewPic">缩小后保存为文件名(包括路径)</param>    
  35. /// <param name="intWidth">缩小至宽度</param>    
  36. public void SmallPic(string strOldPic, string strNewPic, int intWidth)   
  37. {   
  38.   
  39. System.Drawing.Bitmap objPic,objNewPic;   
  40. try   
  41. {   
  42. objPic = new System.Drawing.Bitmap(strOldPic);   
  43. int intHeight=(intWidth / objPic.Width) * objPic.Height;   
  44. objNewPic=new System.Drawing.Bitmap(objPic,intWidth,intHeight);   
  45. objNewPic.Save(strNewPic);   
  46.   
  47. }   
  48. catch(Exception exp){throw exp;}   
  49. finally   
  50. {   
  51. objPic=null;   
  52. objNewPic=null;   
  53. }   
  54. }   
  55.   
  56.   
  57. /// <summary>    
  58. /// 按比例缩小图片,自动计算宽度    
  59. /// </summary>    
  60. /// <param name="strOldPic">源图文件名(包括路径)</param>    
  61. /// <param name="strNewPic">缩小后保存为文件名(包括路径)</param>    
  62. /// <param name="intHeight">缩小至高度</param>    
  63. public void SmallPic(string strOldPic, string strNewPic, int intHeight)   
  64. {   
  65.   
  66. System.Drawing.Bitmap objPic,objNewPic;   
  67. try   
  68. {   
  69. objPic = new System.Drawing.Bitmap(strOldPic);   
  70. int intWidth=(intHeight / objPic.Height) * objPic.Width;   
  71. objNewPic=new System.Drawing.Bitmap(objPic,intWidth,intHeight);   
  72. objNewPic.Save(strNewPic);   
  73.   
  74. }   
  75. catch(Exception exp){throw exp;}   
  76. finally   
  77. {   
  78. objPic=null;   
  79. objNewPic=null;   
  80. }   
  81. }   

asp.net用鼠标滚轮实现图片pdf缩放

  1. <mce:script   language="javascript"><!--  
  2.      
  3. function   bbimg(o)     
  4. {     
  5.       var   zoom=parseInt(o.style.zoom,   10)||100;  
  6.   
  7.      zoom+=event.wheelDelta/12;  
  8.   
  9.      if   (zoom>0)    
  10.   
  11.         o.style.zoom=zoom+'%';     
  12.       return   false;     
  13. }       
  14. // --></mce:script>     
  15.       
  16.        
  17. <img   src='../FloorPicture/<%#DataBinder.EvalContainer.DataItem,"picture")%>'        
  18.   
  19.    onload="javascript:  
  20.   
  21.    if(this.width>screen.width*0.7)  
  22.   
  23.       this.style.width=screen.width*0.7;"    
  24.   
  25.    onmousewheel="return   bbimg(this)">  
  26.    
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  2. <html>  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">  
  5. <title>用滚轮实现图片缩放</title>  
  6. </head>  
  7. <mce:script language="JavaScript"><!--  
  8.     function zoomimg(img){  
  9.     //img.style.zoom获取img对象的缩放比例,并转为十进制整数 pdf 
  10.     var zoom = parseInt(img.style.zoom,10);  
  11.     if (isNaN(zoom)){    //当zoom非数字时zoom默认为100%  
  12.     zoom = 100;  
  13.     }  
  14.     //event.wheelDelta滚轮移动量上移+120,下移-120;显示比例每次增减10%  
  15.     zoom += event.wheelDelta / 12;  
  16.     //当zoom大于10%时重新设置显示比例  
  17.     if (zoom>10) img.style.zoom = zoom + "%";  
  18.     }  
  19. // --></mce:script>  
  20. <body>  
  21. <br>  
  22. <!--onmousewheel:当滚轮移动时触发-->  
  23. <img src="图片路径" mce_src="图片路径" onmousewheel="zoomimg(this)">  
  24. </body>  
  25. </html>  

asp.net:pdf图片按比例缩放,可输入参数设定初始大小pdf

  1. <mce:scriptlanguage="javascript">  
  2. <!--  
  3. //图片按比例缩放,可输入参数设定初始大小   
  4. functionresizeimg(ImgD,iwidth,iheight) {varimage=newImage();  
  5. image.src=ImgD.src;if(image.width>0 && image.height>0){if(image.width/image.height>= iwidth/iheight){if(image.width>iwidth){  
  6. ImgD.width=iwidth;  
  7. ImgD.height=(image.height*iwidth)/image.width;  
  8. }else{  
  9. ImgD.width=image.width;  
  10. ImgD.height=image.height;  
  11. }  
  12. ImgD.alt=image.width+"×"+image.height;  
  13. }else{if(image.height>iheight){  
  14. ImgD.height=iheight;  
  15. ImgD.width=(image.width*iheight)/image.height;  
  16. }else{  
  17. ImgD.width=image.width;  
  18. ImgD.height=image.height;  
  19. }  
  20. ImgD.alt=image.width+"×"+image.height;  
  21. }  
  22.      ImgD.style.cursor="pointer";//改变鼠标指针   
  23.      ImgD.onclick =function() {window.open(ImgD.src);}//点击打开大图片   
  24.     if(navigator.userAgent.toLowerCase().indexOf("ie") > -1) {//判断浏览器,如果是IE   
  25.       ImgD.title ="请使用鼠标滚轮缩放图片,点击图片可在新窗口打开";  
  26.       ImgD.onmousewheel =functionimg_zoom()//滚轮缩放   
  27.       {  
  28.           varzoom = parseInt(this.style.zoom, 10) || 100;  
  29.           zoom +=event.wheelDelta / 12;  
  30.           if(zoom> 0) this.style.zoom = zoom +"%";  
  31.           returnfalse;  
  32.       }  
  33.      }else{//如果不是IE   
  34.             ImgD.title ="点击图片可在新窗口打开";  
  35.          }  
  36. }  
  37. }  
  38. // -->   
  39. </mce:script>  
新浪微博粉丝精灵,刷粉丝、刷评论、刷转发、企业商家微博营销必备工具"
 MyQBlog   浏览(2843)   评论(0)   关键字
  
Copyright © 2010-2020 power by CYQ.Blog - 秋色园 v2.0 All Rights Reserved